Browse Source

important создание изображения при наличии необходимых для этого условий

MIRSPORTA-885 Группировка фотографий
master
Alexander Demidov 7 years ago
parent
commit
8c82ae7ac4
  1. 4
      Image.php
  2. 17
      Upload.php

4
Image.php

@ -84,6 +84,10 @@ abstract class Image extends File
*/
public function getVariant($size, $force_create = false, $important_create = false)
{
if ($force_create && !$important_create && array_key_exists($size, $this->variants) && $this->variants[$size]['size'] === null) {
$important_create = true;
}
return parent::getImageVariant($size, $force_create, $important_create);
}
}

17
Upload.php

@ -109,7 +109,9 @@ abstract class Upload
} else {
$greagwar_image = self::getGreagwarImage($tmp_file_path);
}
$image->type = $greagwar_image->guessType();
if (!Image::getIsSubClass($image)) {
if ( !( ImageVariant::getIsClass( $image ) ) && Image::getIsSubClass( $image ) ) {
$greagwar_image->resize( $width, $height, 0xffffff, $force = false, $rescale = false, $crop = true );
@ -117,8 +119,11 @@ abstract class Upload
$greagwar_image->resize( $width, $height, 0xffffff, $force = false, $rescale = false, $crop = false );
}
}
$hash = $greagwar_image->getHash($image->type, $quality = 100);
$file_path = $greagwar_image->generateFileFromhash($hash) . '.' . $image->type;
if (Image::getIsSubClass($image)) {
if (is_uploaded_file($tmp_file_path)) {
move_uploaded_file($tmp_file_path, $file_path);
@ -128,17 +133,24 @@ abstract class Upload
} else {
if (\Majestic\Config::get('PYTHON_PIL_RESIZE')) {
$script_file_path = \Majestic\Config::get( 'PYTHON_PIL_RESIZE' )->script_file_path;
$pil_options = isset( \Majestic\Config::get( 'PYTHON_PIL_RESIZE' )->pil_options ) ? ' ' . implode( ' ', \Majestic\Config::get( 'PYTHON_PIL_RESIZE' )->pil_options ) : '';
// ob_start();
$code = null;
$command = $script_file_path
. ( ( $width ) ? ' --width=' . $width : '' )
. ( ( $height ) ? ' --height=' . $height : '' )
. $pil_options
. ' ' . $tmp_file_path
. ' ' . $file_path;
ob_start();
passthru( 'exec 2>&1; ' . $command, $code );
if ($code !== 0) {
throw new \ErrorException('Command PYTHON_PIL_RESIZE exit with code "' . $code . '": ' . $command . PHP_EOL . 'Std out: ' . ob_get_clean() );
}
@ -149,10 +161,15 @@ abstract class Upload
}
}
}
$path_parts = pathinfo($file_path);
$image->path = preg_replace('#^' . \Majestic\Config::get('PATH_WEB_ROOT') . '/#', '', $path_parts['dirname']);
$image->filename = $path_parts['basename'];
self::defineSizeWidthAndHeight($image);
unset($greagwar_image);
}

Loading…
Cancel
Save