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


Image::Base::Prima::Image -- draw into Prima image


 use Image::Base::Prima::Image;
 my $image = Image::Base::Prima::Image->new
               (-width => 200, -height => 100);
 $image->line (0,0, 99,99, '#FF00FF');
 $image->rectangle (10,10, 20,15, 'white');


Image::Base::Prima::Image is a subclass of Image::Base::Prima::Drawable,



Image::Base::Prima::Image extends Image::Base to create and draw into Prima::Image objects, including file loading and saving.

See Image::Base::Prima::Drawable for the drawing operations. This subclass adds image creation and file load/save. begin_paint() / end_paint() bracketing is still necessary.

As of Prima 1.28 the supported file formats for both read and write include PNG, JPEG, TIFF, GIF, XBM, XPM and BMP. Prima on X11 draws using the X server, so an X connection is necessary. Don't use Prima::noX11 or drawing operations will quietly do nothing.


See "FUNCTIONS" in Image::Base::Prima::Drawable and "FUNCTIONS" in Image::Base for behaviour inherited from the superclasses.

$image = Image::Base::Prima::Image->new (key=>value,...)

Create and return a new image object. A new Prima::Image object can be created, usually with a -width and -height (but it also works to set them later),

    $ibase = Image::Base::Prima::Image->new
               (-width => 200,
                -height => 100);;

Or an existing Prima::Image object can be given

    $ibase = Image::Base::Prima::Image->new
               (-drawable => $prima_image);
$image->load ()
$image->load ($filename)

Load from -file, or with a $filename argument set -file then load.

The Prima loadExtras option is used so as to get the file format codecID in the underlying image, and any possible "hotspot" for -hotx and -hoty below ("ATTRIBUTES").

$image->save ()
$image->save ($filename)

Save to -file, or with a $filename argument set -file then save to that.

As per Prima save, the file format is taken from the underlying $primaimage->{'extras'}->{'codecID'} if that's set, otherwise from the filename extension. The -file_format attribute below can set the desired output format.


-file (string)

For saving Prima takes the file format from the filename extension, for example ".png". See Prima::image-load.

-file_format (string or undef)

The file format as a string like "PNG" or "JPEG", or undef if unknown or never set. Getting or setting -file_format operates on the $primaimage->{'extras'}->{'codecID'} field of the underlying Prime::Image.

After load the -file_format is the format read. Setting -file_format changes the format for a subsequent save.

-hotx (integer or undef, default undef)
-hoty (integer or undef, default undef)

The cursor hotspot in images with that attribute. These are the hotSpotX and hotSpotY extra in the $primaimage->{'extras'} (see Prima::codecs and "Querying extra information" in Prima::image-load). As of Prima 1.29 they're available from XPM and XBM format files.

-quality_percent (0 to 100 or undef)

The image quality when saving to JPEG format. JPEG compresses by reducing colours and resolution in ways that are not too noticeable to the human eye. 100 means full quality, no such reductions. undef means the Prima default, which is 75.

This becomes the quality parameter to $primaimage->save().


Image::Base, Prima::Image, Prima::image-load, Image::Base::Prima::Drawable

Image::Xpm, Image::Xbm, Image::Base::GD, Image::Base::PNGwriter, Image::Base::Gtk2::Gdk::Pixbuf



Image-Base-Prima is Copyright 2010, 2011, 2015 Kevin Ryde

Image-Base-Prima is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.

Image-Base-Prima is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Image-Base-Prima. If not, see <>.