alexsanqp / watermark
Creating a watermark by position in the image
Installs: 44
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/alexsanqp/watermark
Requires
- yiisoft/yii2: ~2.0.0
This package is not auto-updated.
Last update: 2025-12-28 10:11:44 UTC
README
Creating a watermark by position in the image
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist alexsanqp/watermark "*"
or add
"alexsanqp/watermark": "*"
to the require section of your composer.json file.
Usage
Once the extension is installed, simply use it in your code by :
public function actionWatermark() { $pathToWatermark = '@app/web/img/plusminus-watermark.png'; $pathToImage = '@app/web/img/mountain.jpg'; //If you need to set the image proportions $width = Yii::$app->request->get('width'); $height = Yii::$app->request->get('height'); $watermark = new Watermark($pathToImage, $pathToWatermark); $watermark->setPercentageRatio(0.4); $watermark->setPosition(Position::CENTER, Position::CENTER); $watermark->rotate(-40); if (!empty($width) && !empty($height)) { $watermark->setProportionImage($width, $height); } // append watermark $watermark->watermark(); // Save if ($watermark->save()) { echo $watermark->getSaveImagePath(); } // Or $rawImageWatermark = $watermark->getImageWithWatermark(); if ($rawImageWatermark) { $imageWatermark = imagecreatefromstring($rawImageWatermark->get('jpg')); if ($imageWatermark !== false) { header('Content-Type: image/jpeg'); imagejpeg($imageWatermark, null, 90); imagedestroy($imageWatermark); } } }
