yii2-gallery-manager icon indicating copy to clipboard operation
yii2-gallery-manager copied to clipboard

gallery-manager recompress original images

Open sashsvamir opened this issue 8 years ago • 3 comments

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?

sashsvamir avatar Mar 05 '16 09:03 sashsvamir

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.

zxbodya avatar Mar 05 '16 16:03 zxbodya

with some images recompression gives good quality, but some not. Especially photos with contrasty colors.

almix avatar Mar 16 '16 08:03 almix

@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]];
                    },
                ]
            ]
        ];
    }

maks-sl avatar Dec 18 '17 16:12 maks-sl