【问题标题】:Watermark on animated gif with php带有php的动画gif上的水印
【发布时间】:2012-05-10 09:49:39
【问题描述】:

我需要一个向动画 gif 添加水印的函数。我如何使用 PHP 和 ImageMagick 做到这一点?

这是我的代码,但它不起作用。

function IMagickWatermark($sf, $sfDest, $sfLogo, $sGravity='southeast'){
        //$sCmd = "composite -compose bumpmap -gravity $sGravity $sfLogo \"$sf\" $sfDest";
        $sCmd = "convert \"$sf\" -coalesce -gravity south -draw 'image over 0,0 0,0 \"$sfLogo\"' \"$sfDest\"";
        exec($sCmd);
        return 1;
    }
$sf = $_SERVER['DOCUMENT_ROOT']."/test/source.gif";
$sfDest = $_SERVER['DOCUMENT_ROOT']."/test/dest.gif";
$sfLogo = $_SERVER['DOCUMENT_ROOT']."/test/logowithtext.gif";
IMagickWatermark($sf, $sfDest, $sfLogo, $sGravity='SouthEast');

【问题讨论】:

  • 请贴一些代码。我认为 php 的 gd 库很适合这项工作。
  • StackOverflow 的我们这些人很乐意为您提供帮助,但我们需要了解您已经完成了哪些工作,以及您在哪些方面遇到了困难,以便更好地帮助您。
  • 我编辑了我的问题并添加了我的代码,但它不起作用。
  • @Janus Troelsen,那个脚本:gifbox.ru/test/test.php - 我不知道为什么它没有(:可能是我的主机没有卸载 ImageMagick?我怎么知道?
  • 尝试从主机上的 shell 在命令行 (CLI) 上执行它

标签: php imagemagick gif watermark animated-gif


【解决方案1】:

试试这个:

$animation = ani.gif; 

$watermark = logo.png; 

$watermarked_animation = "morph.gif"; 

$cmd = " $animation -coalesce -gravity South ". 
" -geometry +0+0 null: $watermark -layers composite -layers optimize "; 

exec("convert $cmd $watermarked_animation "); 

【讨论】:

  • 很好的解决方案。谢谢
【解决方案2】:
<?php
shell_exec('for i in sphere*.gif; do convert $i  -font Arial -pointsize 20 \
      -draw "gravity south \
             fill black  text 0,12 \'Copyright\' \
             fill white  text 1,11 \'Copyright\' " \
      wmark_$i; done');

shell_exec("convert   -delay 20   -loop 0   wmark_sphere*.gif   animatespheres.gif");
$f = fopen("animatespheres.gif", 'rb');
fpassthru($f);
fclose($f);
?>

如果您需要调试,请删除 fopen、fpassthru、fclose 行并为 shell_execs 添加 echo。

【讨论】:

  • 什么样的文件:sphere*.gif wmark_sphere*.gif animatespheres.gif 源、目标、带有徽标或文本的文件在哪里?
  • sphere&lt;whatever&gt;.gif 是您的输入文件。 wmark_sphere&lt;whatever&gt;.gif 是生成的临时文件。 animatespheres.gif 是您的结果。没有带有徽标或文本的文件,它是动态生成的。如果您想使用图像添加水印,请阅读以下内容:imagemagick.org/Usage/annotating
  • 它不起作用:&lt;? ini_set("display_errors","1"); ini_set("display_startup_errors","1"); ini_set('error_reporting', E_ALL); $sf = $_SERVER['DOCUMENT_ROOT']."/test/d1cdcdf2cf6dba7a12511d6077783895.gif"; shell_exec("for i in $sf; do convert $i -font Arial -pointsize 20 \ -draw \"gravity south \ fill black text 0,12 'Copyright' \ fill white text 1,11 'Copyright' \" \ wmark_$i; done"); shell_exec("convert -delay 20 -loop 0 wmark_sphere*.gif animatespheres.gif"); fpassthru("animatespheres.gif"); ?&gt; 代码:gifbox.ru/test/index.php
  • 现在试试,我编辑它来修正引号。尝试理解代码。用双引号引用的字符串中的 $a 在 php 中不起作用,因为它认为它是一个 php 变量,即使它不是。这就是我交换引号的原因。
  • 您写道:尝试在命令行 (CLI) 上从主机上的 shell 执行它。我尝试使用命令:“/var/www/gifbox.ru/test/d1cdcdf2cf6dba7a12511d6077783895.gif”-coalesce -gravity south -draw 'image over 0,0 0,0 “/var/www/gifbox.ru/ test/gifboxru.gif"' "/var/www/gifbox.ru/test/_d1cdcdf2cf6dba7a12511d6077783895.gif" 和带水印的 gif 已创建!当我运行 php 脚本时,它没有创建。
猜你喜欢
  • 1970-01-01
  • 2018-01-09
  • 2014-02-28
  • 2016-12-14
  • 2013-09-02
  • 1970-01-01
  • 2010-10-19
  • 1970-01-01
  • 2013-12-22
相关资源
最近更新 更多