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
$newblob = zlibshrink($blob)		#attempt to better compress the PNG
$newblob = filter($blob)		#apply adaptive filtering and then compress

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 in any way) an image data (IDAT) chunk and checks there is an end (IEND) chunk in the right place. From version 0.03 onwards ispng also checks 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.

zlibshrink($blob) will attempt to better compress the supplied PNG and will achieve good results with smallish (ie with only one IDAT chunk) but poorly compressed PNGs.

filter($blob) will attempt to apply some adaptive filtering to the PNG - filtering should deliver compression (though the results can be mixed). Currently this code is under development but it does work on PNG test images and if filtering is not possible (eg the image has already been filtered), then an unchanged image is returned. All PNG compression and filtering is lossless.

LICENCE AND COPYRIGHT

This is free software and is licenced under the same terms as Perl itself ie Artistic and GPL

It is copyright (c) Adrian McMenamin, 2006, 2007

REQUIREMENTS

POSIX
Compress::Zlib

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!

zlibshrink - introduced in version 0.05 - needs to be made to work with PNGs with more than one IDAT chunk

filtering - with all type implement since version 0.1 needs to work with PNGs with more than one IDAT chunk

AUTHOR

Adrian McMenamin <adrian AT newgolddream DOT info>

SEE ALSO

Image::Magick