2017 © Pedro Pelรกez
 

library php-watermark

Add text or image watermark on images.

image

ajaxray/php-watermark

Add text or image watermark on images.

  • Friday, July 20, 2018
  • by ajaxray
  • Repository
  • 3 Watchers
  • 27 Stars
  • 2,375 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 11 Forks
  • 5 Open issues
  • 4 Versions
  • 50 % Grown

The README.md

PHPWatermark

SensioLabsInsight Latest Stable Version Build Status Coverage Status Total Downloads License, (*1)

Add text or image Watermark on image and PDF using PHP and ImageMagick., (*2)

Pre-requisite

PHP ImageMagick extension is not required., (*3)

Installation

Add as a dependency with composer, (*4)

bash $ composer require ajaxray/php-watermark Or download latest version as a Zip file., (*5)

For PHP versions >= 5.6 to <8 use v0.1.2 bash $ composer require ajaxray/php-watermark:v0.1.2 Also you should check older readme file for PHP version <8, (*6)

### How to use?, (*7)

```php <?php // Initiate with source image or pdf $watermark = new Watermark('/path/to/source.jpg');, (*8)

 // Customize some options (See list of supported options below)
 $watermark->withText('ajaxray.com')
    ->setFontSize(48)
    ->setRotate(30)
    ->setOpacity(.4)
    ->write('path/to/output.jpg');


 // Watermark with Image
 $watermark->withImage('path/to/logo.png')
    ->setPosition(Watermark::POSITION_BOTTOM_RIGHT)
    ->setStyle(Watermark::STYLE_IMG_DISSOLVE)
    ->write('path/to/output.jpg');

``` If output file name is skipped for Watermark::write() function, the source file will be overridden., (*9)

### Customization options, (*10)

The table below shows customization options and their support matrix. Listed functions should be called on an object of Ajaxray\PHPWatermark\Watermark. Checkmark column titles means the following -, (*11)

  • Txt-Img: Watermarking with text on Image (sample, sample-tiled)
  • Img-Img: Watermarking with Image on Image (sample)
  • Txt-PDF: Watermarking with text on PDF (sample)
  • Img-PDF: Watermarking with Image on PDF (sample)

โŒ› = coming soon!, (*12)

Function Value Txt-Img Img-Img Txt-PDF Img-PDF
setFont('Arial') string; Font Name โœ… โœ…
setFontSize(36) int; Font size โœ… โœ…
setOpacity(.4) float; between 0 (opaque) to 1 (transparent) โœ… โœ… โœ… โœ…
setRotate(245) int; between 0 to 360 โœ… โœ…
setPosition($position) int; One of Watermark::POSITION_* constants โœ… โœ… โœ… โœ…
setOffset(50, 100) int, int; X and Y offset relative to position โœ… โœ… โœ… โœ…
setStyle($style) int; One of Watermark::STYLE_* constants โŒ› โœ… โŒ› โŒ›
setTiled() boolean; (default true) โœ… โœ… โŒ› โŒ›
setTileSize(200, 150) int, int; Width and Height of each tile โœ… โŒ›

BTW, all the samples linked above are the results of [these examples][9]. You may generate them yourself just by running example scripts from command line -, (*13)

$ php vendor/ajaxray/php-watermark/examples/example_img.php
$ php vendor/ajaxray/php-watermark/examples/example_pdf.php

Then you should get the result files in vendor/ajaxray/php-watermark/examples/img and vendor/ajaxray/php-watermark/examples/pdf directories., (*14)

Something unexpected? Debug! ๐Ÿž๐Ÿ”ซ

If anything unexpected happened, try to debug the issue., (*15)

  1. First step is to check if PHP is configured to display errors. Alternatively you may add these lines at the top of your script. php ini_set('display_errors', 1); error_reporting(E_ALL);
  2. A common reason of not getting expected result is mistakes in filepaths. You may try logging / printing source and destination file paths.
  3. Check the permission of the parent directory of destination path. Destination directory indicates -
    • The file path mentioned in the second argument of Watermark::withText() and Watermark::withImage() methods.
    • Parent of the source file itself if no separate destination mentioned in above methods.
  4. There is Watermark::setDebug() method which will make Watermark object to return imagemagick command instead of executing it. Then, you may run the output manually to check if there is any error in underlying imagemagick commands.

Notes:

  • To see the list of supported font names in your system, run convert -list font on command prompt
  • Remember to set appropriate output file extension (e,g, .pdf for pdf files)
  • If possible, use absolute path for files to avoid various mistakes.
  • STYLE_IMG_* constants are for Image watermarks and Watermark::STYLE_TEXT_* are for text.
  • Default text style (Watermark::STYLE_TEXT_BEVEL) is expected to be visible on any background. Use other text styles only on selective backgrounds.
  • UnitTest are executed and all green against PHP 5.6 and PHP 7.1 using PHPUnit 5.7.5
  • I'v tested all intended functionality with ImageMagick 7.0.4-6 Q16 x86_64 and GPL Ghostscript 9.20 installed.

Important Update for PDF watermarking:

When using the imagemagick + ghostscript extraction and joining pdf pages, it has a few drawbacks including file-size issue. Many developers were asking for a solution about the file size and PDF quality since releasing of this library. So, I've created a command line tool for PDF watermarking that will work without converting pages into images. As a result, you'll get better PDF quality and dramatically smaller file size., (*16)

https://github.com/ajaxray/markpdf, (*17)

Please note that, it's not a PHP library. So you've to use it using [exec][10], [shell_exec][11] or [Symfony Process Component][12]., (*18)


"This is the Book about which there is no doubt, a guidance for those conscious of Allah" - Al-Quran, (*19)

The Versions

20/07 2018

dev-master

9999999-dev http://github.com/ajaxray/php-watermark

Add text or image watermark on images.

  Sources   Download

MIT

The Requires

  • php >=5.6 || >=7.0

 

The Development Requires

by Anis Uddin Ahmad

image watermark image-manipulation imagemagick-watermark imagemagick-wrapper

18/03 2017

v0.1.1

0.1.1.0 http://github.com/ajaxray/php-watermark

Add text or image watermark on images.

  Sources   Download

MIT

The Requires

  • php >=5.6 || >=7.0

 

The Development Requires

by Anis Uddin Ahmad

image watermark image-manipulation imagemagick-watermark imagemagick-wrapper

17/03 2017

v0.1.0

0.1.0.0 http://github.com/ajaxray/php-watermark

Add text or image watermark on images.

  Sources   Download

MIT

The Requires

  • php >=5.6 || >=7.0

 

The Development Requires

by Anis Uddin Ahmad

image watermark image-manipulation imagemagick-watermark imagemagick-wrapper

03/03 2017

v0.0.1

0.0.1.0 http://github.com/ajaxray/php-watermark

Add text or image watermark on images.

  Sources   Download

MIT

The Requires

  • php >=5.6 || >=7.0

 

by Anis Uddin Ahmad

image watermark image-manipulation imagemagick-watermark imagemagick-wrapper