2017 © Pedro Peláez
 

library watermark

Creating a watermark by position in the image

image

alexsanqp/watermark

Creating a watermark by position in the image

  • Thursday, July 5, 2018
  • by alexsanqp
  • Repository
  • 1 Watchers
  • 1 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Yii2 library Watermark

Creating a watermark by position in the image, (*1)

Installation

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)

Usage

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)

The Versions

05/07 2018

dev-master

9999999-dev

Creating a watermark by position in the image

  Sources   Download

MIT

The Requires

 

library yii2 image photo watermark