【问题标题】:How to add Watemark logo in a GIF image?如何在 GIF 图片中添加水印标志?
【发布时间】:2014-02-26 21:43:06
【问题描述】:

您好,我想创建一个水印 GIF 图片。

请检查我的代码:

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>

上面的代码正在运行。但问题是当我上传 GIF 图像时,它会创建水印图像,但 GIF 图像不是动画。

任何人都可以帮助我..如何使用动画 GIF 创建水印图像?

【问题讨论】:

    标签: php image gif watermark


    【解决方案1】:

    嗯,the PHP manual 明确指出:

    注意: 将动画 GIF 文件读入内存时,图像资源指针中只返回第一帧。

    在该页面上的一个注释中,有人提到http://www.gdenhancer.com/ 是一个很好的替代方案,但它确实适用于动画 gif。不过我自己没有任何经验。

    【讨论】:

      【解决方案2】:

      经过大量研究,终于找到了制作水印gif图像的解决方案。

      你需要imagick和magickwand

      试试这个对你有帮助的代码:

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

      谢谢

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-08-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-02-16
        相关资源
        最近更新 更多