Switch branches/tags
Clone or download
MaizerGomes and ajaxray Enable checking of imagemagick installation (#11)
Thanks @MaizerGomes for this essential requirement cheking πŸ‘
Latest commit 923a7f9 Jul 20, 2018


SensioLabsInsight Latest Stable Version Build Status Coverage Status Total Downloads License

Add text or image Watermark on image and PDF using PHP and ImageMagick.


PHP ImageMagick extension is not required.


Add as a dependency with composer

$ composer require ajaxray/php-watermark

Or download latest version as a Zip file.

How to use?

    // Initiate with source image or pdf
    $watermark = new Watermark('/path/to/source.jpg');
    // Customize some options (See list of supported options below)
    // Watermark with Text
    $watermark->withText('', 'path/to/output.jpg');
    // Watermark with Image
    $watermark->withImage('path/to/logo.png', 'path/to/output.jpg');

If output file name is skipped for Watermark::withImage() and Watermark::withText() function, the source file will be overridden.

Customization options

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 -

  • 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!

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 βœ… βŒ›

Also, there is Watermark::setDebug() which will make Watermark object to return imagemagick command instead of executing it.

BTW, all the samples linked above are the results of these examples. You may generate them yourself just by running example scripts from command line -

$ 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.


  • 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.

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