Gif Image is not animated after making watermark

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
chinmay235
Posts: 2
Joined: 2014-02-04T07:56:56-07:00
Authentication code: 6789

Gif Image is not animated after making watermark

Post 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. :(
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Gif Image is not animated after making watermark

Post by fmw42 »

see http://www.imagemagick.org/Usage/anim_m ... ite_single

or just add the watermark to each frame separately and reanimate
chinmay235
Posts: 2
Joined: 2014-02-04T07:56:56-07:00
Authentication code: 6789

Re: Gif Image is not animated after making watermark

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Gif Image is not animated after making watermark

Post 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
psanjib
Posts: 20
Joined: 2014-02-04T23:03:41-07:00
Authentication code: 6789

Re: Gif Image is not animated after making watermark

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Gif Image is not animated after making watermark

Post 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>";}
psanjib
Posts: 20
Joined: 2014-02-04T23:03:41-07:00
Authentication code: 6789

Re: Gif Image is not animated after making watermark

Post 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 />
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Gif Image is not animated after making watermark

Post by snibgo »

v6.2.8 is very very old. I suggest you upgrade.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Gif Image is not animated after making watermark

Post 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
psanjib
Posts: 20
Joined: 2014-02-04T23:03:41-07:00
Authentication code: 6789

Re: Gif Image is not animated after making watermark

Post 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" />
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Gif Image is not animated after making watermark

Post 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.
psanjib
Posts: 20
Joined: 2014-02-04T23:03:41-07:00
Authentication code: 6789

Re: Gif Image is not animated after making watermark

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Gif Image is not animated after making watermark

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Gif Image is not animated after making watermark

Post 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>";}
?>
psanjib
Posts: 20
Joined: 2014-02-04T23:03:41-07:00
Authentication code: 6789

Re: Gif Image is not animated after making watermark

Post 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
Post Reply