NAME

App::MathImage::Gtk2::Ex::GdkPixbufBits -- misc pixbuf helpers

SYNOPSIS

use App::MathImage::Gtk2::Ex::GdkPixbufBits;

FUNCTIONS

App::MathImage::Gtk2::Ex::GdkPixbufBits::save ($pixbuf, $filename, $type, key => value, ...)
@args = App::MathImage::Gtk2::Ex::GdkPixbufBits::save_options ($type, key => value, ...)

save() saves a Gtk2::Gdk::Pixbuf with options adapted to what the Gtk in use supports. save_options() adapts options and returns them.

The idea is to pass a full set of options which are automatically reduced if not applicable to the $type or not available at all. For example the compression option must be set different ways for PNG or for TIFF. The two separate compression options here are used according to the $type.

zlib_compression (integer 0 to 9 or -1)

A Zlib style compression level. For $type "png" in Gtk 2.8 this becomes the compression option.

tiff_compression_type (integer or names "none", "huffman", "lzw", "jpeg" or "deflate")

A TIFF compression method. For $type "tiff" in Gtk 2.20 this becomes the compression option. String names "deflate" etc are converted to the corresponding integer value.

quality_percent (0 to 100)

An image quality percentage, for lossy formats such as JPEG. For $type "jpeg" this becomes the quality option.

tEXt:foo (string)

A PNG style keyword string. For $type "png" in Gtk 2.8 this is passed through as tEXt, with a utf8::upgrade if necessary in Gtk2-Perl 1.221, and moved to before any compression option as a workaround for a Gtk bug.

For example

App::MathImage::Gtk2::Ex::GdkPixbufBits::save
  ($pixbuf,        # Gtk2::Gdk::Pixbuf object
   $user_filename, # eg. string "/tmp/foo"
   $user_type,     # eg. string "png"
   zlib_compression      => 9,
   quality_percent       => 100,
   tiff_compression_type => "deflate",
   tEXt:Author           => "Yorick");
   
$format = App::MathImage::Gtk2::Ex::GdkPixbufBits::filename_to_format ($filename)

Return the Gtk2::Gdk::PixbufFormat for the given $filename based on its extension. For example foo.png is PNG format. If the filename is not recognised then return undef.

PixbufFormat is new in Gtk 2.2. Currently filename_to_format throws an error in Gtk 2.0. Would returning undef be better?

App::MathImage::Gtk2::Ex::GdkPixbufBits::format_matches_filename ($format, $filename)

$format should be a Gtk2::Gdk::PixbufFormat object. Return true if one of its extensions matches $filename. For example JPEG format matches foo.jpg or foo.jpeg.