dev-master
9999999-devCreating a watermark by position in the image
MIT
The Requires
library yii2 image photo watermark
 Wallogit.com
                    
                    2017 © Pedro Peláez
                         Wallogit.com
                    
                    2017 © Pedro Peláez
                    
                    
                    
                    
                
                
            
Creating a watermark by position in the image
Creating a watermark by position in the image, (*1)
The preferred way to install this extension is through composer., (*2)
Either run, (*3)
php composer.phar require --prefer-dist alexsanqp/watermark "*"
or add, (*4)
"alexsanqp/watermark": "*"
to the require section of your composer.json file., (*5)
Once the extension is installed, simply use it in your code by :, (*6)
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);
        }
    }
}
 , (*7)
, (*7)
Creating a watermark by position in the image
MIT
library yii2 image photo watermark