Extend Image class. Separate to ImageVariant. Remove _is_new_record.

This commit is contained in:
Alexander Demidov
2013-05-27 12:49:32 +04:00
parent 47d0c54ef1
commit 4ace9e1b02
5 changed files with 97 additions and 77 deletions

View File

@ -19,7 +19,6 @@ abstract class Upload
{
$image = new Image;
$image->original_filename = $file['name'];
$image->type = $file['type'];
$greagwar_image = self::getGreagwarImage($file['tmp_name']);
self::saveImage($image, $greagwar_image);
if ($force_create_variants) {
@ -40,16 +39,17 @@ abstract class Upload
*/
public static function saveImage($image, $greagwar_image, $width = null, $height = null, $crop = true)
{
$greagwar_image = clone($greagwar_image);
if ($width || $height) {
$greagwar_image->resize($width, $height, 0xffffff, false, false, $crop);
}
$file_path = $greagwar_image->cacheFile($greagwar_image->guessType(), 87, true);
$image->type = $greagwar_image->guessType();
$file_path = $greagwar_image->cacheFile($image->type, 87, true);
$image->size = filesize($file_path);
$path_parts = pathinfo($file_path);
$image->path = preg_replace('#^' . self::PATH_ROOT . '/#', '', $path_parts['dirname']);
$image->filename = $path_parts['basename'];
$image->width = $greagwar_image->width();
$image->height = $greagwar_image->height();
$image->setIsNotEmpty();
}
}