Question

Hi i want to create a watermark GIF image.

Please check my code :

func.php

<?php
function allowed_image($file_name){
    $allow_set = array('gif','GIF');
    $file_ext =   (explode('.', $file_name));
    $end = end($file_ext);  
    return (in_array($end , $allow_set) === true) ? true : false;   
}

function watermark_image($file, $destination){
    $watermark = imagecreatefrompng('logo.png'); 
    $source = getimagesize($file); 

    $source_mime = $source['mime']; 
    image = imagecreatefromgif($file);

    imagecopy($image, $watermark, 70, 160, 0, 0, imagesx($watermark),imagesy($watermark));  
    imagepng($image, $destination); 
    imagedestroy($image); 
    imagedestroy($watermark);
}
?>

test.php

<?php
include('func.php');
if (isset($_FILES['image'])){
     $file_name =       $_FILES['image']['name']; 
     $file_tmp =        $_FILES['image']['tmp_name'];   
     $name = explode('.', $file_name);
     if (allowed_image($file_name) === true){
        $file_name = time() .'.gif';
        watermark_image($file_tmp, 'upload/' . $file_name);       
     } else{
      echo '<p>Please upload only gif image.</p>';
     }
 }
?>
<form enctype="multipart/form-data" method="post">
    <input type="file" name="image" /><input type="submit" value="Go" name="submit" />
</form>

Above code is working. But problem is when i upload GIF image it creates Watermark image but the GIF image is not animated.

Anybody can help me.. How to create watermark image with animated GIF?

Was it helpful?

Solution 2

After lots of research, finally i got the solution for making watermark gif image.

You need imagick and magickwand

Try this code it will help to you:

exec("/usr/local/bin/convert mygif.gif null: watermark-logo.png -gravity SouthEast -layers composite -layers optimize mygif.gif 2>&1",$out,$returnval);

Thanks

OTHER TIPS

Well, the PHP manual clearly states:

Note: When reading animated GIF files into memory, only the first frame is returned in the image resource pointer.

In one of the notes on that page, someone mentions http://www.gdenhancer.com/ as a good alternative that does work with animated gifs though. I don't have any experience with it myself though.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top