Open nazakar opened 8 years ago
Yes.
http://imagine.readthedocs.org/en/latest/usage/introduction.html#image-watermarking
You can do it in versions
functions.
Thanks, but i can't find versions functions in GalleryBehavior vestions declaration is public $versions; Thanks
I mean versions field in behavior configuration, it would be something like:
public function behaviors()
{
return [
'galleryBehavior' => [
'class' => GalleryBehavior::className(),
'type' => 'product',
'extension' => 'jpg',
'directory' => Yii::getAlias('@webroot') . '/images/product/gallery',
'url' => Yii::getAlias('@web') . '/images/product/gallery',
'versions' => [
'medium' => function ($img) {
/** @var Imagine\Image\ImageInterface $img */
$dstSize = $img->getSize();
$maxWidth = 800;
if ($dstSize->getWidth() > $maxWidth) {
$dstSize = $dstSize->widen($maxWidth);
}
// load watermark
$watermark = $imagine->open('/my/watermark.png');
$wSize = $watermark->getSize();
// calculare watermark posiotion
$bottomRight = new Imagine\Image\Point($dstSize->getWidth() - $wSize->getWidth(), $dstSize->getHeight() - $wSize->getHeight());
return $img
->copy()
->resize($dstSize)
// draw watermark
->paste($watermark, $bottomRight);
},
]
]
];
}
Thank, I'll try
Unfortunately - after this, no medium image created and error "NetworkError: 500 Internal Server Error - http://localhost/property/backend/property/galleryApi?type=img&behaviorName=galleryBehavior&galleryId=1&action=ajaxUpload" my watermark is Yii::getAlias('@front').'/uploads/cancel-off.png'
can you show your error? and maybe code you have?
I paste your code with path to my image
It is just an example... I have not tested it.
Maybe error is here $watermark = $imagine->open('/my/watermark.png');
Try replacing it with:
$watermark = Image::getImagine()->open('/my/watermark.png');
still error
2016-02-09 18:07 GMT+02:00 Bogdan Savluk notifications@github.com:
It is just an example... I have not tested it. Maybe error is here $watermark = $imagine->open('/my/watermark.png');
Try replacing it with: $watermark = Image::getImagine()->open('/my/watermark.png');
— Reply to this email directly or view it on GitHub https://github.com/zxbodya/yii2-gallery-manager/issues/25#issuecomment-181931232 .
Nazelina Karanfilian
i simply put this code in my view $imagine = new \Imagine\Imagick\Imagine(); $watermark = $imagine->open(Yii::getAlias('@front').'/uploads/cancel-off.png'); $image1 = $imagine->open('../uploads/small.jpg'); $size = $image->getSize(); $wSize = $watermark->getSize();
$bottomRight = new Imagine\Image\Point($size->getWidth() - $wSize->getWidth(), $size->getHeight() - $wSize->getHeight());
$image1->paste($watermark, $bottomRight); and i get Imagick not installed, maybe the problem is with instance Please Help me
Finally, worked!!! Thanks Code is $imagine= Image::getImagine(); $watermark =$imagine->open(Yii::getAlias('@front').'/uploads/cancel-off.png'); //Yii::getAlias('@front').'/uploads/cancel-off.png'; $wSize = $watermark->getSize(); //calculare watermark posiotion $bottomRight = new \Imagine\Image\Point($dstSize->getWidth() - $wSize->getWidth(), $dstSize->getHeight() - $wSize->getHeight());
return $img
->copy()
->resize($dstSize)
->paste($watermark, $bottomRight);
and don't forget use yii\imagine\Image;
Is it possible to create watermark for images? Thanks