yii2-gallery-manager
yii2-gallery-manager copied to clipboard
gallery-manager recompress original images
Gallery-image save added file with original image size but not original file content. I want use original image files without recompression, its possible with native func of gallery-manager?
Hi,
For now it is not possible, you will need to modify extension... All uploaded images are loaded using Imagine::open(), that after modifications for specific image version, are saved using ImageInterface::save(), I am not sure but on some drivers for Imagine it may preserve original file.
It was done this way, because it was easier to implement and saving original file typically is not required.
with some images recompression gives good quality, but some not. Especially photos with contrasty colors.
@almix, try my solution, just return array as result of function, when you declare behavior in model (like below)
@zxbodya, worth to add this capability to you readme file, also this is forgotten at description of $versions
field of your behavior
public function behaviors()
{
return [
'galleryBehavior' => [
'class' => GalleryBehavior::className(),
'tableName' => '{{%stream_entries_gallery}}',
'type' => 'entry',
'extension' => 'jpg',
'hasName' => false,
'directory' => Yii::getAlias('@staticRoot') . '/stream/entry/gallery',
'url' => Yii::getAlias('@static') . '/stream/entry/gallery',
'versions' => [
'small' => function ($img) {
/** @var Imagine\Image\ImageInterface $img */
return $img
->copy()
->thumbnail(new Imagine\Image\Box(200, 200));
},
'medium' => function ($img) {
/** @var Imagine\Image\ImageInterface $img */
$dstSize = $img->getSize();
$maxWidth = 1200;
if ($dstSize->getWidth() > $maxWidth) {
$dstSize = $dstSize->widen($maxWidth);
}
return [$img
->copy()
->resize($dstSize),
['quality' => 100]];
},
]
]
];
}