如何用PHP添加我的图像gif的水印?

时间:2013-08-13 14:11:02

标签: php image gif watermark shell-exec

我试试这个:

$path = $_SERVER['DOCUMENT_ROOT'].$_SERVER['REQUEST_URI'];
$image = imagecreatefromstring(file_get_contents($path));

$w = imagesx($image);
$h = imagesy($image);

$centerX=round($w/4);
$centerY=round($h/2);

$watermark = imagecreatefrompng('lool-face.png');
$ww = imagesx($watermark);
$wh = imagesy($watermark);

imagecopy($image, $watermark, $centerX, $centerY, 0, 0, $ww, $wh);

eregi('\.(gif|jpeg|jpg|png)$',$path,$regs);
switch( $regs[1] ) {
case 'gif':
   header('Content-type: image/gif');
   imagegif($image);
   break;

但这不起作用,图像是凝固的。

试试这个:

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);

这段代码不起作用我不知道为什么不这样做。 我们希望你有一个Gif htaccess可以在gifs水印中使用的目录

2 个答案:

答案 0 :(得分:1)

这个课程可能是你的解决方案:
PHP Classes transparent watermark

答案 1 :(得分:1)

请看下面的链接。我在php中做了同样的事情。我希望这会对你有所帮助。 https://dl.dropboxusercontent.com/u/58146160/watermark%20image.rar