Refactoring with use of separate to sub classes from Image. Add FileHelper to trying toString conversion. Add ImageCollection (not tested work).
This commit is contained in:
@ -11,27 +11,34 @@ abstract class Upload
|
||||
return $greagwar_image;
|
||||
}
|
||||
/**
|
||||
* @param $class string
|
||||
* @param $file array (ex. ['tmp_name' => '...', 'name' => '...', 'type' => '...'])
|
||||
* @param $force_create_variants bool
|
||||
* @return Image
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public static function image($file, $force_create_variants = true)
|
||||
public static function image($class, $file, $force_create_variants = true)
|
||||
{
|
||||
$image = new Image;
|
||||
/**
|
||||
* @var $image Image
|
||||
*/
|
||||
Image::checkSubClass($class);
|
||||
$image = new $class;
|
||||
$image->original_filename = $file['name'];
|
||||
$greagwar_image = self::getGreagwarImage($file['tmp_name']);
|
||||
self::saveImage($image, $greagwar_image);
|
||||
if ($force_create_variants) {
|
||||
foreach (Image::$sizes as $size) {
|
||||
$sizes = $image->getSizes();
|
||||
foreach ($sizes as $size) {
|
||||
$size_parts = explode('x', $size);
|
||||
self::saveImage($image->getVariant($size), $greagwar_image, $size_parts[0] ? : null, $size_parts[1] ? : null);
|
||||
self::saveImage($image->getImageVariant($size), $greagwar_image, $size_parts[0] ? : null, $size_parts[1] ? : null);
|
||||
}
|
||||
}
|
||||
return $image;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $image Image
|
||||
* @param $image ImageVariant
|
||||
* @param $greagwar_image GreagwarImage
|
||||
* @param null $width
|
||||
* @param null $height
|
||||
|
Reference in New Issue
Block a user