Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Let's finish Imager::GIF

by Anonymous Monk
on Feb 06, 2020 at 21:42 UTC ( #11112516=perlmeditation: print w/replies, xml ) Need Help??

Imager::GIF - a handy module for animated GIF processing - is a nice thought, with one semi-working method and problematic documentation (Re^2: Imager::GIF seems broken), that needs some help, as the docs say:

    TODO

    Implement the rest of the transformations (cropping, rotating etc).

I needed to non-proportionally scale animated GIFs and implemented type=>nonprop in the scale method. Other desirable features include crop, watermark, and sharpening. Please share your mods and methods here.

TODO:

  • https://metacpan.org/pod/distribution/Imager/lib/Imager/Transformations.pod
  • https://metacpan.org/pod/distribution/Imager/lib/Imager/Filters.pod

    Your local file:

    perl -MImager::GIF -le 'for (keys %INC) { print $INC{$_} if /GIF\.pm/ +}'
    My scale method:
    sub scale { my ($self, %args) = @_; my $ratio = $args{scalefactor} // 1; my $qtype = $args{qtype} // 'mixing'; # add qtype support $self->_mangle(sub { my $img = shift; my $ret = $img->scale(%args, qtype => $qtype); my $h = $img->tags(name => 'gif_screen_height'); my $w = $img->tags(name => 'gif_screen_width'); # add non-proportional scaling if ( $args{xpixels} and $args{ypixels} and $args{type} and $args{type} eq 'nonprop') { my $xratio = defined $args{xpixels} ? $args{xpixels} / $w : $ratio; my $yratio = defined $args{ypixels} ? $args{ypixels} / $w : $ratio; $ret->settag(name => 'gif_left', value => int($xratio * $img->tags(name => 'gif +_left'))); $ret->settag(name => 'gif_top', value => int($yratio * $img->tags(name => 'gif +_top'))); $ret->settag(name => 'gif_screen_width', value => int($xr +atio * $w)); $ret->settag(name => 'gif_screen_height', value => int($yr +atio * $h)); } else { # proportional scaling, from the original unless ($ratio) { if (defined $args{xpixels}) { $ratio = $args{xpixels} / $w; } if (defined $args{ypixels}) { $ratio = $args{ypixels} / $h; } } $ret->settag(name => 'gif_left', value => int($ratio * $img->tags(name => 'gif +_left'))); $ret->settag(name => 'gif_top', value => int($ratio * $img->tags(name => 'gif +_top'))); $ret->settag(name => 'gif_screen_width', value => int($ra +tio * $w)); $ret->settag(name => 'gif_screen_height', value => int($ra +tio * $h)); } return $ret; }); }
    Thank you!
  • Replies are listed 'Best First'.
    A reply falls below the community's threshold of quality. You may see it by logging in.

    Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Node Status?
    node history
    Node Type: perlmeditation [id://11112516]
    Approved by erzuuli
    help
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (7)
    As of 2020-04-08 23:15 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      The most amusing oxymoron is:
















      Results (46 votes). Check out past polls.

      Notices?