The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Image::Pngslimmer - slims (dynamically created) PNGs

SYNOPSIS

$ping = ispng($blob)			#is this a PNG? $ping == 1 if it is
$newblob = discard_noncritical($blob)  	#discard non critcal chunks and return a new PNG
my @chunklist = analyze($blob) 		#get the chunklist as an array

DESCRIPTION

Image::Pngslimmer aims to cut down the size of PNGs. Users pass a PNG to various functions (though only one presently exists - Image::Pngslimmer::discard_noncritical($blob)) and a slimmer version is returned. Image::Pngslimmer is designed for use where PNGs are being generated on the fly and where size matters - eg for J2ME use. There are other options - probably better ones - for handling static PNGs.

Call discard_noncritical($blob) on a stream of bytes (eg as created by Perl Magick's Image::Magick package) to remove sections of the PNG that are not essential for display.

Do not expect this to result in a big saving - the author suggests maybe 200 bytes is typical - but in an environment such as the backend of J2ME applications that may still be a worthwhile reduction..

discard_noncritical($blob) will call ispng($blob) before attempting to manipulate the supplied stream of bytes - hopefully, therefore, avoiding the accidental mangling of JPEGs or other files. ispng checks for PNG definition conformity - it looks for a correct signature, an image header (IHDR) chunk in the right place, looks for (but does not check beyond CRC values) an image data (IDAT) chunk and checks there is an end (IEND) chunk in the right place. Versions earlier than 0.03 do not check CRC values.

analyze($blob) is supplied for completeness and to aid debugging. It is not called by discard_noncritical but may be used to show 'before-and-after' to demonstrate the savings delivered by discard_noncritical.

REQUIRES

String::CRC32

LICENCE AND COPYRIGHT

This code is free software is licenced under the same terms as perl itself. It is copyright Adrian McMenamin, 2006, 2007.

TODO

To make Pngslimmer really useful it needs to construct grayscale PNGs from coloured PNGs and paletize true colour PNGs. I am working on it!

AUTHOR

Adrian McMenamin <adrian AT newgolddream DOT info>

SEE ALSO

<Image::Magick>