kaia/watermarking

PHP Packages for adding watermark on image

v1.0.3 2025-02-20 16:42 UTC

This package is auto-updated.

Last update: 2025-06-20 17:25:42 UTC


README

PHP Package where you can insert your own watermark on image. This package using PHP-GD for generating the watermark, so make sure you have PHP-GD installed before you use this package. For now this package only support on 4 positions, and will get update on future.

Requirement

  • php >= 8.0
  • php-gd

Installation

To install this package, run

  composer require kaia/watermarking

Now you can use it into your PHP project

  use Kaia\Watermarking\Watermark;

  /** Example create watermark using text
  Watermark::createFromText($sourcePath, $destinationPath, $watermarkText, $options[]);

  /** Example create watermark using image
  Watermark::createFromImage($sourcePath, $destinationPath, $watermarkPath, $options[]);

Available options

For "createFromText" method.

Key Type Value Default Value Note
position string top-left, top-right, bottom-left, bottom-right top-left optional
size integer any number 12 optional
color string hex color code (example #ffffff) #ffffff optional
font string path to your .ttf file arial.ttf optional

For "createFromImage" method.

Key Type Value Default Value Note
position string top-left, top-right, bottom-left, bottom-right top-left optional
opacity integer between 0.1 - 1.0 0.5 optional
scale integer between 0.1 - 1.0 0.2 optional

Example case :

I want create watermark with text "I am Kaia" on existing image :

  • Source Image Path = storage/images/image.jpeg
  • Destination Image Path = storage/images/watermarked/watermarked.jpeg
  • Watermark Position = Top Left
  • Watermark Font Size = 16
  • Font Path = storage/fonts/arial.ttf
  use Kaia\Watermarking\Watermark;

  Watermark::createFromText(
    'storage/images/image.jpeg', 
    'storage/images/watermarked/watermarked.jpeg', 
    'I am Kaia', 
    [
      'position' => 'top-left',
      'size' => '16',
      'font' => 'storage/fonts/arial.ttf'
    ]
  );

And the output will be like : Image

Support me

https://ko-fi.com/kaia3