NAME

Image::GIF::Encoder::PP - Pure perl GIF encoding

SYNOPSIS

use Image::GIF::Encoder::PP;
my $palette = pack('CCCCCC', 0xFF, 0xFF, 0xFF, 0xDA, 0x09, 0xFF);               # Pack the RGB color pallete
my $gif = Image::GIF::Encoder::PP->new('out.gif', 200, 200, $palette, 1, 0, 0); # create a 200x200 infinitely looping 1 bit color palette transparent gif
$gif->{'frame'} = pack('x10000');                                               # set the pixels of the frame to palette index 0 (transparent in this case)
Image::GIF::Encoder::PP::scale($frame, 100, 100, 2, \$destframe);               # scale a 100x100 frame by 2 and store in $destframe
$gif->add_frame(5);                                                             # add a frame with a 5 ms delay
undef $gif;                                                                     # finish writing to gif

CONSTRUCTOR

$gif = Image::GIF::Encoder::PP->new($filename, $width, $height, $palette, $depth, $loop, $transparent_index)

Constructs a new GIF object.

If $filename is defined, a file will be created, otherwise it will write the image to STDOUT.

$palette is a binary array of RGB24 its length should correspond to bitdepth $depth. 2 colors (6 bytes) for a bitdepth of 1, 4 colors, (12 bytes) for a bitdepth of 2, etc.

$loop controls how many times to loop, 0 loops infinitely, 1 or a negative value should play once with most players.

$transparent_index marks a color index to show as transparent instead of that color. Use -1 if there is not transparent index.

ADDING IMAGE DATA

Set $gif->{'frame'} to your binary array of pixels, one byte per pixel corresponding to a palette index.

For example to set a 100x100 frame to the first color index $gif->{'frame'} = pack('x10000')

$gif->add_frame($delay)

Adds the image data from $gif->{'frame'} to the GIF where $delay is the number of milliseconds between each frame.

WRAPPING UP

undef $gif

The final image data is flushed when the $gif object is DESTROYed.

UTILITY FUNCTIONS

Image::GIF::Encoder::PP::scale($frame, $w, $h, $times, \$destframe)

Scales a $wx$h frame by $times and stores it in the $destframe buffer. If you wish to make a scaled gif, be sure to adjust the $width and $height appropriately. For example 100x100 frames scaled by 2 needs a 200x200 $gif.

Image::GIF::Encoder::PP::expand_frame($frame, $srcbitsperpixel, $desiredbitsperpixel)

Converts a frame from $srcbitsperpixel to $desiredbitsperpixel and returns the resulting frame. For creating a gif with Image::GIF::Encoder::PP $desiredbitsperpixel should be 8.

AUTHOR

Gavin Hayes, <gahayes at cpan.org>

SUPPORT AND DOCUMENTATION

You can find documentation for this module with the perldoc command.

perldoc Image::GIF::Encoder::PP

Support and bug reports can be found at the repository https://github.com/G4Vi/gifenc-pl

LICENSE AND COPYRIGHT

This software is copyright (c) 2021-2022 by Gavin Hayes.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.