watermark on animated gif

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
chesca_martinez

watermark on animated gif

Post by chesca_martinez »

hello iam new here.
i want to put a watermark on animated gif, transparent/non transparent gif and jpg.
i tried to research and found that only imagemagick can do it with animated gif.
i dont know any thing about imagemagick.
so do any of you has a script that will put watermark on my images?
thanks in advance.
defied

Re: watermark on animated gif

Post by defied »

Code: Select all

convert animated.gif null: watermark.png -layers Composite out.gif
you may have to coalesce the animated gif first?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: watermark on animated gif

Post by anthony »

See IM examples, Animation Modification
http://imagemagick.org/Usage/anim_mods/

You may like to go through Animation Basics to, just so you knwo what you are doing! :)
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
chesca_martinez

Re: watermark on animated gif

Post by chesca_martinez »

@all
i dont know anything about im. my site is hosted on dreamhost and according to them im is installed in all their servers http://wiki.dreamhost.com/index.php/Image_Magick.
so i tried to run the script theyve provided below which is

Code: Select all

<?php
       $location='/usr/bin/convert';
       $command='-thumbnail 150';
       $name='glass.';
       $extfrm='jpg';
       $extto='png';
       $output="{$name}{$extto}";
       $convert=$location . ' ' .$command . ' ' . $name . $extfrm . ' ' . $name . $extto;
       exec ($convert);
       print "<img src=" . $output . ">";
   ?>
and it works. ironically this is the only working script i see the uses im.

@defied
thanks but i dont know how to use nor where to put the code you gave.
i edited the code and this is what i got

Code: Select all

<?php
       $location='/usr/bin/convert';
       $command='convert img.jpg null: watermark.png -layers Composite out.gif';
       exec ($command);
       print "<img src=out.jpg>";
?>
i dont know how to code in im.
can you pls help me?

i want to put watermark on animated gif.

thanks in advance
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: watermark on animated gif

Post by anthony »

Repleace "convert" in your second line with "/usr/bin/convert"

that will work, mostly.

however BOTh their script and yours will fail when multiple peopel try to use it simultaniously.

A filename is used and while one users browser is reading the fimage file they created, another user could also be attempting to create another image in the same file name, temporarilly destorying the first users attempt to read their image! That is the above is BAD PROGRAMMING

If a temporary image file is needed, that file should be created as a separate image filename. Also the above scripts do not provide any way to delete the image file created at a later date. I supose a later program (or the same one) could delete old images that presumably are no longer required, but again that is bad practice.

The best solution is to have the script output two things. A first call of the script returns the HTML page. The image link in that page however calls the script again with appropriate arguments to generate and output an image, as an image HTTP result, and not save it to disk or use temporary files.

That is the better solution, though much more complex.

Prehaps Bonzo from Rubbleweb can provide an example of such a dual output generator.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
chesca_martinez

Re: watermark on animated gif

Post by chesca_martinez »

thanks anthony,
well actually i will be the only one who will use it. i mean, i just want to put watermarks on my images before i uploaded it on the web.
i have at least 1000 animated gifs, jpg and gifs and so i want to use it to watermark all my images by batch.

i cant find any premade script that does that.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: watermark on animated gif

Post by anthony »

A PHP script may not be the best method for batching. You are probably better off using the command line with some wrappers. See IM Examples, basics, mogrify, for examples of using mogrify and other command line methods of batch processing lots of files.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: watermark on animated gif

Post by Bonzo »

From one of Anthonys previous posts

Code: Select all

exec("convert $animation -coalesce -gravity Center -geometry +0+0 null: $watermark -layers composite -layers optimize $watermarked_animation ");
Your should be able to build this into a php program BUT layers may not wor depending on what version of ImageMagick you have.
Display IM version with this:

Code: Select all

<?php
echo "<pre>";
system("convert -version");  
echo "</pre>";
?> 
See what layer operators are supported with this:

Code: Select all

<?php
echo "<pre>";
system("convert -list layers");
echo "</pre>";
?> 
If you want to watermark 1000's of gifs you had better do them in batches or else your server will come to a halt and your hosts will not be very happy.

Watermark an image "On the fly"

Code: Select all

<?php

$animation = "original.gif";

$watermark = "output.png";

$cmd = "convert $animation -coalesce -gravity Center -geometry +0+0 null: $watermark -layers composite -layers optimize GIF:-";

header("Content-type: image/gif");
passthru($cmd, $retval);
?>
chesca_martinez

Re: watermark on animated gif

Post by chesca_martinez »

@anthony
thank you so much.

@bonzo
thanks, i have
Version: ImageMagick 6.2.4 09/16/06 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2005 ImageMagick Studio LLC

while nothing shows with the "supoprted layers"

the 2 codes above does not work with me. maybe its bec of the "layers" thing.

i got this from rubblewebs and it works (i just dont like it bec the watermark is opaque and does not support animated gif)

Code: Select all

<?php
exec("composite -watermark 30% -tile ../original_images/boots.png ../original_images/House.jpg watermark_image_multi.jpg");
?>
well this one works with animated gif with annotate function but the text is not that readable and had bad animation(text).

Code: Select all

<?
$animation = "animated2.gif";
$watermark = "watermark.png";
$watermarked_animation = "out62.gif";

exec("convert $animation -pointsize 12 -font Verdana -fill rgb\(0,0,0\) -gravity southeast -annotate +0+0 'TEST' $watermarked_animation "); 
print "<img src=$watermarked_animation>";
?>
pls help me
thanks again.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: watermark on animated gif

Post by anthony »

The layers composite options was added much later than that version. However if you watermark overlay is constant thne you should be able to use a -draw command to overlay a single layers image onto the coalesced animation.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
chesca_martinez

Re: watermark on animated gif

Post by chesca_martinez »

thanks, so you mean i should do this?

Code: Select all

<?php

$animation = "original.gif";

$watermark = "output.png";

$cmd = "convert $animation -coalesce -gravity Center -geometry +0+0 null: $watermark -draw composite -draw optimize GIF:-";

header("Content-type: image/gif");
passthru($cmd, $retval);
?>
i tried it on both animated gif and jpg it works but the watermark is "flashing"
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: watermark on animated gif

Post by anthony »

I suggest you read IM examples throughly!

Code: Select all

<?php

$animation = "original.gif";
$watermark = "output.png";

$cmd = "convert $animation -coalesce -gravity Center -draw "image 0,0 0,0 '$watermark' " -layers optimize GIF:-";

header("Content-type: image/gif");
passthru($cmd, $retval);
?>
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
chesca_martinez

Re: watermark on animated gif

Post by chesca_martinez »

oh pls dont get angy with me anthony. its very hard to learn a foreign language in 3 days.

btw i installed the imagemagick in my pc bec i had problems with my webhost that has a lower version of im. i can now do it with "layers" yippie! :lol:

but i have some problems with some images. whenever i view an animated gif on my local drive it shows crap animation but when it is viewed in browsers(ie, ff, opera and safari) the animated gifs are ok.

i also have problem with jpgs, the quality is far worst than the original with a very slight difference in file size. but when i convert the jpgs to gif it not only reduces the file size by very great amount it also has better quality.

thanks.
hope will get help again.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: watermark on animated gif

Post by anthony »

oh pls dont get angy with me anthony. its very hard to learn a foreign language in 3 days.
Applogies, just answered about a dozen or so queries in which the answer is clearly defined within IM examples.

How are you viewing the animatied GIF??? Presumably not with the IM "animate" comand which I know works properly, at least under Linux. Under windows I don't know what you use. The browser is probably the best method.

JPEG's are a lossy image file format. The act of reading decoding and writing the image data in a JPEG will degrade the image data as it is not saves to be reproduced eactaly but in a manner than comresses very well for minimal human eye differences, at least with a reasonable quality. That is not to say that for some images like cartoon like images it produces a good result. For exactness use PNG instead, but expect a larger image file.

I would never say GIF has good quality, exact for limited color images. GIF only allows 256 colors, one of which can be pure transparency, Colors are also only 8bit depth, and only RGB colorspaces. That is why it is so much smaller, it has less colors in it.

See the two format summeries in IM examples, one in "Common File Formats", the other in "Thumbnailing".
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
chesca_martinez

Re: watermark on animated gif

Post by chesca_martinez »

heres a sample of animated gif that ive generated.
Image

whenever i view this in any browsers i cant see the distorted layer. but when i preview it on my computer(windows picture viewer) i can see the distorted layer.
Post Reply