PHP script to add transparent logo on multiple images

PHP script to add transparent logo on multiple images

I will show you how you can add transparent logo or icon watermark using php script on multiple images and save result images. You can align logo or icon using perimeters which are used in imagecopy() php function.

For multiple images Copy and paste the below code in your php file and run.I'm using the following code to add image or logo on multiple images.

//$logo is the logo or icon which you to add on a image
//$background is the background image
//$arrayBackground add multiple images to add add logo on them in array
$logo = imagecreatefrompng('1.png');
$arrayBackground = array('2.jpg','3.jpg','4.jpg','5.jpg');
foreach($arrayBackground as $image){
    $background = imagecreatefromjpeg($image);
    $size = getimagesize($image);

    // you can align the logo according the size of the background image
    $marge_right = $size[0] - 130;
    $marge_bottom = 1;
    $sx = imagesx($logo);
    $sy = imagesy($logo);

    //pass the size, images parametres in imagecopy() function 
    imagecopy($background, $logo, imagesx($background) - $sx - $marge_right, imagesy($background) - $sy - $marge_bottom, 0, 0, imagesx($logo), imagesy($logo));

    header('Content-type: image/png');
    $imgName = time()+rand() .".png";
    imagepng($background, $imgName);
    //create and save new image in your current directory


Hi, I'm Saurav, the developer behind usingphp. Donate to help me keep usingphp free and maintained.

Please let me know what your thoughts or comments are on this article. If you have any suggestion or found any mistake in this article then please let us know.

Latest Comments

Add your comment