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

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.

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

AUTHOR

Adrian McMenamin <adrian AT newgolddream DOT info>

SEE ALSO

Image::Magick