SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    Thinking! Lord Brar's Avatar
    Join Date
    Jun 2004
    Posts
    787
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Possible to watermark animated GIFs?

    I've been trying to find an answer to this but my effort so far has been futile. I was wondering if anyone could help me here.

    Is it anyhow possible to watermark animated GIF images using GD or ImageMagick.

    Also, is it anyhow possible to detect if the uploaded GIF image is animated or not?

    Thanks!

  2. #2
    My true identity MaxS's Avatar
    Join Date
    Nov 2004
    Location
    New York
    Posts
    768
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm interested in knowing the answer as well. I have tried doing it myself and it seems to kill the animation when you watermark it.

  3. #3
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Presently any tampering with an animated gif will result in it breaking. GD takes the image as a single frame and resends it back as a single frame.

    Whilst on my loafings around php.net, i came across this script for detecting if a gif is animated or not....
    PHP Code:
    <?php

    function is_ani($filename)
    {
           
    $filecontents=file_get_contents($filename);

           
    $str_loc=0;
           
    $count=0;
           while (
    $count 2# There is no point in continuing after we find a 2nd frame
           
    {

                   
    $where1=strpos($filecontents,"\x00\x21\xF9\x04",$str_loc);
                   if (
    $where1 === FALSE)
                   {
                           break;
                   }
                   else
                   {
                           
    $str_loc=$where1+1;
                           
    $where2=strpos($filecontents,"\x00\x2C",$str_loc);
                           if (
    $where2 === FALSE)
                           {
                                   break;
                           }
                           else
                           {
                                   if (
    $where1+== $where2)
                                   {
                                           
    $count++;
                                   }
                                   
    $str_loc=$where2+1;
                           }
                   }
           }

           if (
    $count 1)
           {
                   return(
    true);

           }
           else
           {
                   return(
    false);
           }
    }

    exec("ls *gif" ,$allfiles);
    foreach (
    $allfiles as $thisfile)
    {
           if (
    is_ani($thisfile))
           {
                   echo 
    "$thisfile is animated<BR>\n";
           }
           else
           {
                   echo 
    "$thisfile is NOT animated<BR>\n";
           }
    }
    ?>
    Dont know if it works or not as I didn't write it!

    This script and a few other tips can be found on ww.php.net/imagecreatefromgif

    Cheers
    Spike
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  4. #4
    Thinking! Lord Brar's Avatar
    Join Date
    Jun 2004
    Posts
    787
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by spikeZ
    Presently any tampering with an animated gif will result in it breaking. GD takes the image as a single frame and resends it back as a single frame.

    Whilst on my loafings around php.net, i came across this script for detecting if a gif is animated or not....
    PHP Code:
    <?php

    function is_ani($filename)
    {
           
    $filecontents=file_get_contents($filename);

           
    $str_loc=0;
           
    $count=0;
           while (
    $count 2# There is no point in continuing after we find a 2nd frame
           
    {

                   
    $where1=strpos($filecontents,"\x00\x21\xF9\x04",$str_loc);
                   if (
    $where1 === FALSE)
                   {
                           break;
                   }
                   else
                   {
                           
    $str_loc=$where1+1;
                           
    $where2=strpos($filecontents,"\x00\x2C",$str_loc);
                           if (
    $where2 === FALSE)
                           {
                                   break;
                           }
                           else
                           {
                                   if (
    $where1+== $where2)
                                   {
                                           
    $count++;
                                   }
                                   
    $str_loc=$where2+1;
                           }
                   }
           }

           if (
    $count 1)
           {
                   return(
    true);

           }
           else
           {
                   return(
    false);
           }
    }

    exec("ls *gif" ,$allfiles);
    foreach (
    $allfiles as $thisfile)
    {
           if (
    is_ani($thisfile))
           {
                   echo 
    "$thisfile is animated<BR>\n";
           }
           else
           {
                   echo 
    "$thisfile is NOT animated<BR>\n";
           }
    }
    ?>
    Dont know if it works or not as I didn't write it!

    This script and a few other tips can be found on ww.php.net/imagecreatefromgif

    Cheers
    Spike
    Thanks A LOT spike. Gonna try it out and would let you know. Too bad that GIFs can't be watermarked...

  5. #5
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    im sure you can do it. it may be a lot of effort depending on existing software available to support your task.

    they make software to edit animated gifs. so php can do it too, although it might be possible to just execute an external peice of software to do it for you and return the result to php.

  6. #6
    SitePoint Zealot
    Join Date
    Mar 2002
    Location
    UK
    Posts
    150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can watermark animation with text in imagemagick using the following command:

    Code:
    convert youranimation.gif -gravity center -fill black -annotate +1+1 "Watermark" -fill white -annotate +0+0 "Watermark" youranimationwm.gif

  7. #7
    Thinking! Lord Brar's Avatar
    Join Date
    Jun 2004
    Posts
    787
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mpw
    You can watermark animation with text in imagemagick using the following command:

    Code:
    convert youranimation.gif -gravity center -fill black -annotate +1+1 "Watermark" -fill white -annotate +0+0 "Watermark" youranimationwm.gif
    WOW! Do you have any link which explain this process in more depth.

    Thanks for the pointer mpw.

  8. #8
    SitePoint Zealot
    Join Date
    Mar 2002
    Location
    UK
    Posts
    150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This method is documented here. Although it seems there's some unnecessary code included on there for this particular method.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •