(none) imager-devel
/ help / lists / applications / search /
 

Re: scaling animated GIFs

From: Bernhard Graf (
16812@xyz.molar.is)
Date: Fri 15 Jun 2007 - 20:58:18 GMT

  • Next message: Bernhard Graf: "Re: scaling animated GIFs"

    Tony Cook wrote:

    > In general Imager considers the tags on an image to be opaque and
    > doesn't try to manipulate them, beyond populating them when the image
    > is read in and using them when the image is written.
    >
    > Unfortunately you'll need to transform/copy the tags yourself.
    >
    > Note that in your case, if the images have non-zero gif_left/gif_top
    > values, presumably they're smaller than the gif_screen_width /
    > gif_screen_height, so scaling them all to the same size will produce
    > some strange results.

    I must admit, that I don't know about the exact meaning of these values.
    Do you have a source that illustrates these? AFAIK it is possible that
    these values might differ in a GIF animation.

    Aside from that I would assume, that scaling these values through a
    simple rule of three would be correct:

      $factor_x = $out->getwidth / $in->getwidth;
      $factor_y = $out->getheight / $in->getheight;
      $gif_left = $in->tags(name => 'gif_left') * $factor_x;
      $gif_top = $in->tags(name => 'gif_top') * $factor_y;
      $screen_width = $in->tags(name => 'gif_screen_width') * $factor_x;
      $screen_height = $in->tags(name => 'gif_screen_height') * $factor_y;

    > In most cases I expect you'll just need to copy gif_delay:

    The problem is, that from the current documentation I get no idea what
    tags are important for writing (or other subsequent processing).

    > # you don't need to create an image object for read_multi(), since
    > # it's a class method
    > my @in = Imager->read_multi(file => $infile, type => 'gif')
    > or die Imager->errstr;
    > my @out;
    > for my $i (@in) {
    > my $out = $i->scale(xpixels => 60, ypixels => 60, type=>'min');
    > $out->settag(gif_delay => $i->tags(name=>'gif_delay'));

    Sidenote:
    I'd wish settag() would actually work like above instead of the clumsy
    settag(name => 'gif_delay', value => $i->tags(name=>'gif_delay'));
    Or even better: Class::Accessor style (where $img->tags holds a
    container object for the image's tags):
    $out->tags->gif_delay($in->tags->gif_delay);

    > push @out, out;
    > }
    > Imager->write_multi({file => $outfile, type => 'gif'}, @out)
    > or die Imager->errstr;
    >
    > Tony

    -- 
    Bernhard Graf
    



  •