Page 1 of 5

Gif Image is not animated after making watermark

Posted: 2014-02-04T08:09:33-07:00
by chinmay235
I have added PHP watermark animated image but i have faced problem the orginal.gif image is not animated after creating the watermark. :(

Code: Select all

<?php
$image = new Imagick();
$image->readImage("orginal.gif");

$watermark = new Imagick();
$watermark->readImage("watermark.png");

// how big are the images?
$iWidth = $image->getImageWidth();
$iHeight = $image->getImageHeight();
$wWidth = $watermark->getImageWidth();
$wHeight = $watermark->getImageHeight();

if ($iHeight < $wHeight || $iWidth < $wWidth) {
    // resize the watermark
    $watermark->scaleImage($iWidth, $iHeight);

    // get new size
    $wWidth = $watermark->getImageWidth();
    $wHeight = $watermark->getImageHeight();
}

// calculate the position
$x = ($iWidth - $wWidth) / 2;
$y = ($iHeight - $wHeight) / 2;

$image->compositeImage($watermark, imagick::COMPOSITE_OVER, $x, $y);

header("Content-Type: image/" . $image->getImageFormat());
echo $image;
?>
orginal.gif
Image

watermark.jpg
Image

Output:
Image

Description: I have a form there is option to upload file, Upload file only accept gif image after upload the gif image the gif image will show with the logo watermark in the site. But when give watermark image the watermark GIF image is not animated. :(

Re: Gif Image is not animated after making watermark

Posted: 2014-02-04T11:32:32-07:00
by fmw42
see http://www.imagemagick.org/Usage/anim_m ... ite_single

or just add the watermark to each frame separately and reanimate

Re: Gif Image is not animated after making watermark

Posted: 2014-02-04T22:14:27-07:00
by chinmay235
Subject: Gif Image is not animated after making watermark
fmw42 wrote:see http://www.imagemagick.org/Usage/anim_m ... ite_single

or just add the watermark to each frame separately and reanimate
Hi fmw42,
I am completely unknown about ImageMagic. Give me some idea how to create GIF animated Watermark image in PHP.

I saw your above link that is some code is available but where i use that code?

Code: Select all

convert canvas_prev.gif -gravity center \
          -fill black     -annotate +1+1 "Copyright" \
          -fill white     -annotate +0+0 "Copyright" \
          annotate.gif
  gif_anim_montage annotate.gif annotate_frames.gif
Give some idea in above code. How to use that code in PHP?

viewtopic.php?f=2&t=24925&p=107530#p107523

Re: Gif Image is not animated after making watermark

Posted: 2014-02-04T22:28:05-07:00
by fmw42
I do not know Imagick that well. But in command line or using PHP exec(), this works fine.

Code: Select all

convert h8Hjm.gif null: WFr1K.png  -gravity Center -layers composite -layers optimize animation.gif
Image

Re: Gif Image is not animated after making watermark

Posted: 2014-02-04T23:13:48-07:00
by psanjib
Hi, i have same problem while user water mark on animated gif image, the animation not working.
i have used

Code: Select all

<?php  
$image= exec('convert ani.gif null: logo.png  -gravity Center -layers composite -layers optimize animation.gif');
echo $image;
?>
but that won't working. can you tell me how could i use this command get the final image with water mark.

Re: Gif Image is not animated after making watermark

Posted: 2014-02-05T00:19:53-07:00
by fmw42
I don't know why it does not work? Try putting the full path to convert in your command. Also try using double quotes rather than single quotes.

What version of IM are you using and what platform? Do you get any error messages?

to get error messages try

Code: Select all

exec("path2/convert ani.gif null: logo.png  -gravity Center -layers composite -layers optimize animation.gif",$out,$returnval);
foreach($out as $text)
{echo "$text<br>";}

Re: Gif Image is not animated after making watermark

Posted: 2014-02-05T00:47:36-07:00
by psanjib
My imagick version is 6.2.8 i have no error while run this page

if i use the below code that is working fine

Code: Select all

<?php exec('convert ani.gif -resize 50% rose.gif'); ?>
<img src=rose.gif />
but i don't know why not working the below script

Code: Select all

<?php exec('convert ani.gif null: logo.png  -gravity Center -layers composite -layers optimize animation.gif'); ?>
<img src='animation.gif' />

while run this file the below php warning write in error_log file
[05-Feb-2014 02:09:50 America/Chicago] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20090626/magickwand.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20090626/magickwand.so: cannot open shared object file: No such file or directory in Unknown on line 0
[05-Feb-2014 02:09:50 America/Chicago] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20090626/ixed.5.3.lin' - /usr/local/lib/php/extensions/no-debug-non-zts-20090626/ixed.5.3.lin: cannot open shared object file: No such file or directory in Unknown on line 0
i hope that won't be a problem because while i run the below code same warning write in error_log file and the that code works fine

Code: Select all

<?php exec('convert ani.gif -resize 50% rose.gif'); ?>
<img src=rose.gif />

Re: Gif Image is not animated after making watermark

Posted: 2014-02-05T06:06:35-07:00
by snibgo
v6.2.8 is very very old. I suggest you upgrade.

Re: Gif Image is not animated after making watermark

Posted: 2014-02-05T10:59:33-07:00
by fmw42
The layers composite code and/or that kind of animation modification was probably not implemented until after IM 6.2.8. As snibgo says, that is over 600 versions old and you should try to upgrade if you can. Otherwise, there is likely no fix for that command.

The only other way, would be to write a script to loop over each frame of the animation separately and composite the watermark image into them. Then regenerate you animation. You could likely use mogrify to do the composite rather than a script loop. see
http://www.imagemagick.org/Usage/basics ... fy_compose

Re: Gif Image is not animated after making watermark

Posted: 2014-02-10T04:04:10-07:00
by psanjib
Now i upgrade my image magic version to 6.6.3, now will that work, because i have tested and it seems don't work.
below is my code

Code: Select all

<?php exec("convert h8Hjm.gif null: WFr1K.png  -gravity Center -layers composite -layers optimize animation.gif"); ?>
<img src="animation.gif" />

Re: Gif Image is not animated after making watermark

Posted: 2014-02-10T11:07:18-07:00
by fmw42
Do you get any error messages when run as

Code: Select all

exec("convert h8Hjm.gif null: WFr1K.png  -gravity Center -layers composite -layers optimize animation.gif",$out,$returnval);
foreach($out as $text)
{echo "$text<br>";}
The command works for me in command line mode as far back as IM 6.7.5.5 (as far back as I can test). Can you test in command line rather than PHP?

IM 6.6.3 is still very old.

You might need to add the full path to convert in your PHP command.

Re: Gif Image is not animated after making watermark

Posted: 2014-02-14T00:08:50-07:00
by psanjib
I have updated the version `6.8.8-5`still not working, please help me its urgent.

or else anybody know how to get all frame from a gif image

Re: Gif Image is not animated after making watermark

Posted: 2014-02-14T09:17:20-07:00
by snibgo
Your command works fine for me, v6.8.8-0 on Windows 8.1, at the command line.

Please put your source images somewhere like dropbox.com and paste the links here.

Re: Gif Image is not animated after making watermark

Posted: 2014-02-14T13:06:05-07:00
by fmw42
Does convert work to do other things? If not then you probably need to put the full path to convert.

try

<?php
echo "<pre>";
system("type -a convert");
echo "</pre>";
?>

and see where it says IM convert resides.

Also what do you get from the error messages using something like

<?php
exec("convert h8Hjm.gif null: WFr1K.png -gravity Center -layers composite -layers optimize animation.gif",$out,$returnval);
foreach($out as $text)
{echo "$text<br>";}
?>

Re: Gif Image is not animated after making watermark

Posted: 2014-02-14T23:54:59-07:00
by psanjib
now i am using

Code: Select all

<?php exec("/usr/bin/convert h8Hjm.gif null: WFr1K.png -gravity Center -layers composite -layers optimize animation.gif",$out,$returnval);
foreach($out as $text)
{echo "$text<br>";}
?>
convert is /usr/bin/convert

also i am using windows 7
while i run this in php i got below warning warning message

PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20090626/magickwand.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20090626/magickwand.so: cannot open shared object file: No such file or directory in Unknown on line 0

no echo, animation.gif not created