2948 explained code solutions for 75 technologies


php-gdHow to add watermark to image


<?php

$big = '/var/www/examples/heroine.png';
$small = '/var/www/examples/small.png';

$bg = imagecreatefrompng($big);
$wm = imagecreatefrompng($small);

$size = getimagesize($small);

imagecopy($bg, $wm, 100, 100, 0, 0, $size[0], $size[1]);

imagePng($bg, '/tmp/image.png');ctrl + c
$bg

image to add watermark to

$wm

watermark

getimagesize

returns image size from given path

imagecreatefrompng

creates GD image object from given PNG image

imagecopy

adds $wm watermark image to $bg image

imagePng

saves image in PNG format to the given path


How to add watermark to image, php gd

Usage example

<?php

$big = '/var/www/examples/heroine.png';
$small = '/var/www/examples/small.png';

$bg = imagecreatefrompng($big);
$wm = imagecreatefrompng($small);

$size = getimagesize($small);

imagecopy($bg, $wm, 100, 100, 0, 0, $size[0], $size[1]);

imagePng($bg, '/tmp/image.png');