@ -13,7 +13,7 @@ abstract class Upload
}
/**
* @ param $class string
* @ param $class string | Image
* @ param $file array ( ex . [ 'tmp_name' => '...' , 'name' => '...' , 'type' => '...' ])
* @ param $force_create_variants bool
* @ param int $quality
@ -26,19 +26,26 @@ abstract class Upload
/**
* @ var $image Image
*/
if ( is_null ( $class ) || $class == '' ) {
throw new ErrorException ( 'Class not defined.' );
}
if ( ! is_object ( $class ) && ! class_exists ( $class )) {
throw new ErrorException ( 'Class "' . $class . '" not exists.' );
}
Image :: checkSubClass ( $class );
$image = new $class ;
$image = is_object ( $class ) ? $class : new $class ;
$image -> original_filename = $file [ 'name' ];
$greagwar_image = self :: getGreagwarImage ( $file [ 'tmp_name' ]);
self :: saveImage ( $image , $greagwar_image , null , null , true , $quality );
self :: saveImage ( $image , $greagwar_image , $class :: getMaxWidth (), $class :: getMaxHeight () , $quality );
if ( $force_create_variants ) {
$sizes = $image -> getSizes ();
foreach ( $sizes as $size ) {
$size_parts = explode ( 'x' , $size );
self :: saveImage ( $image -> getImageVariant ( $size ), $greagwar_image , $size_parts [ 0 ] ? : null , $size_parts [ 1 ] ? : null , true , $quality );
self :: saveImage ( $image -> getImageVariant ( $size ), $greagwar_image , $size_parts [ 0 ] ? : null , $size_parts [ 1 ] ? : null , $quality );
}
}
// В случае, если был передан объект, возвращение результата не имеет значения
return $image ;
}
@ -47,14 +54,20 @@ abstract class Upload
* @ param $greagwar_image GreagwarImage
* @ param null $width
* @ param null $height
* @ param bool $crop TODO : разъяснить за что отвечает этот " магический " параметер
* @ param int $quality
* TODO : Сделать возможность передавать параметры для метода _resize ()
*/
public static function saveImage ( $image , $greagwar_image , $width = null , $height = null , $crop = true , $ quality = 87 )
public static function saveImage ( $image , $greagwar_image , $width = null , $height = null , $quality = 87 )
{
if ( ! ImageVariant :: getIsClass ( $image ) && is_null ( $width ) && is_null ( $height )) {
if ( Image :: getIsSubClass ( $image )) {
$width = $image :: getMaxWidth ();
$height = $image :: getMaxHeight ();
}
}
$greagwar_image = clone ( $greagwar_image );
if ( $width || $height ) {
$greagwar_image -> resize ( $width , $height , 0xffffff , false , false , $crop );
$greagwar_image -> resize ( $width , $height , 0xffffff , $force = true , $rescale = tru e, $crop = false );
}
$image -> type = $greagwar_image -> guessType ();
$file_path = $greagwar_image -> cacheFile ( $image -> type , $quality , true );