Browse Source

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

MIRSPORTA-885 Группировка фотографий
master
Alexander Demidov 8 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) 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); return parent::getImageVariant($size, $force_create, $important_create);
} }
} }

17
Upload.php

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

Loading…
Cancel
Save