简体   繁体   English

如何在GIF图像中添加Watemark徽标?

[英]How to add Watemark logo in a GIF image?

Hi i want to create a watermark GIF image. 嗨,我想创建水印GIF图像。

Please check my code : 请检查我的代码:

func.php 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 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. 但是问题是当我上传GIF图像时,它会创建水印图像,但GIF图像没有动画。

Anybody can help me.. How to create watermark image with animated GIF? 任何人都可以帮助我。如何用动画GIF创建水印图像?

Well, the PHP manual clearly states: 好吧, PHP手册明确指出:

Note: When reading animated GIF files into memory, only the first frame is returned in the image resource pointer. 注意:将动画GIF文件读入内存时,图像资源指针中仅返回第一帧。

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. 在该页面上的注释之一中,有人提到http://www.gdenhancer.com/是可用于动画gif的一个很好的选择。 I don't have any experience with it myself though. 我自己没有任何经验。

After lots of research, finally i got the solution for making watermark gif image. 经过大量研究,最终我得到了制作水印gif图像的解决方案。

You need imagick and magickwand 您需要imagick和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 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM