The different image formats can write different image type, and some have different options to control
how the images are written.
When you call write() or write_multi() with an option that has the same name as a tag for the image
format you're writing, then the value supplied to that option will be used to set the corresponding tag
in the image. Depending on the image format, these values will be used when writing the image.
This replaces the previous options that were used when writing GIF images. Currently if you use an
obsolete option, it will be converted to the equivalent tag and Imager will produced a warning. You can
suppress these warnings by calling the Imager::init() function with the "warn_obsolete" option set to
false:
Imager::init(warn_obsolete=>0);
At some point in the future these obsolete options will no longer be supported.
PNM(PortableaNyMap)
Imager can write "PGM" (Portable Gray Map) and "PPM" (Portable PixMaps) files, depending on the number of
channels in the image. Currently the images are written in binary formats. Only 1 and 3 channel images
can be written, including 1 and 3 channel paletted images.
$img->write(file=>'foo.ppm') or die $img->errstr;
Imager can read both the ASCII and binary versions of each of the "PBM" (Portable BitMap), "PGM" and
"PPM" formats.
$img->read(file=>'foo.ppm') or die $img->errstr;
PNM does not support the spatial resolution tags.
The following tags are set when reading a PNM file:
•
"pnm_maxval" - the "maxvals" number from the PGM/PPM header. Always set to 2 for a "PBM" file.
•
"pnm_type" - the type number from the "PNM" header, 1 for ASCII "PBM" files, 2 for ASCII "PGM"
files, 3 for ASCII c<PPM> files, 4 for binary "PBM" files, 5 for binary "PGM" files, 6 for binary
"PPM" files.
The following tag is checked when writing an image with more than 8-bits/sample:
•
pnm_write_wide_data - if this is non-zero then write() can write "PGM"/"PPM" files with
16-bits/sample. Some applications, for example GIMP 2.2, and tools can only read 8-bit/sample binary
PNM files, so Imager will only write a 16-bit image when this tag is non-zero.
JPEG
You can supply a "jpegquality" parameter ranging from 0 (worst quality) to 100 (best quality) when
writing a JPEG file, which defaults to 75.
$img->write(file=>'foo.jpg', jpegquality=>90) or die $img->errstr;
If you write an image with an alpha channel to a JPEG file then it will be composed against the
background set by the "i_background" parameter (or tag), or black if not supplied.
Imager will read a gray scale JPEG as a 1 channel image and a color JPEG as a 3 channel image.
$img->read(file=>'foo.jpg') or die $img->errstr;
The following tags are set in a JPEG image when read, and can be set to control output:
• "jpeg_density_unit" - The value of the density unit field in the "JFIF" header. This is ignored on
writing if the "i_aspect_only" tag is non-zero.
The "i_xres" and "i_yres" tags are expressed in pixels per inch no matter the value of this tag, they
will be converted to/from the value stored in the JPEG file.
• "jpeg_density_unit_name" - This is set when reading a JPEG file to the name of the unit given by
"jpeg_density_unit". Possible results include "inch", "centimeter", "none" (the "i_aspect_only" tag
is also set reading these files). If the value of "jpeg_density_unit" is unknown then this tag isn't
set.
• "jpeg_comment" - Text comment.
• "jpeg_progressive" - Whether the JPEG file is a progressive file. (Imager 0.84)
JPEG supports the spatial resolution tags "i_xres", "i_yres" and "i_aspect_only".
You can also set the following tags when writing to an image, they are not set in the image when reading:
• "jpeg_optimize" - set to a non-zero integer to compute optimal Huffman coding tables for the image.
This will increase memory usage and processing time (about 12% in my simple tests) but can
significantly reduce file size without a loss of quality.
• "jpeg_compress_profile" - set to either "fastest", the default, or only with "MozJPEG", to "max".
Setting this to any other value will cause an error, failing the write() call. Setting this to "max"
without "MozJPEG" will cause an error.
use Imager::File::JPEG;
my $prof = Imager::File::JPEG->is_mozjpeg ? "max" : "fastest";
$im->write(file => "foo.jpeg", jpeg_compress_profile => $prof)
or die $im->errstr;
Note that unlike "MozJPEG", Imager always defaults to "fastest".
• "jpeg_tune" - corresponds to the "MozJPEG" "cjpeg" "-tune" parameters, this can be any of:
• "psnr"
• "ssim"
• "ms-ssim"
• "hvs-psnr"
These set the same values as the "jpeg_base_quant_tbl_idx", "jpeg_lambda_log_scale1",
"jpeg_lambda_log_scale2" and "jpeg_use_lambda_weight_tbl" tags, which can override the values set by
"jpeg_tune".
Unlike "cjpeg" "-tune", "jpeg_tune" doesn't force the quality to 75.
Requires that Imager::File::JPEG was built with "MozJPEG".
• "jpeg_arithmetic" - if set to non-zero, use arithmetic coding when writing the image. This requires
that the "libjpeg" variant that Imager::File::JPEG was built with had encode support for arithmetic
coding enabled when it was built.
•
"jpeg_jfif" - if set to zero, disable writing the JFIF header even if one is technically required,
which it is for the color spaces Imager works with. This saves 18 bytes in the output file and most
applications including web browsers will successfully read the file, but your experience may differ.
This will prevent the "i_xres", "i_yres" and "jpeg_density_units" tags from having an effect.
• "jpeg_smooth" - if set to a value from 1 to 100 apply smoothing to the image to eliminate dithering
noise (without modifying the Imager image). Default: 0 (no smoothing).
•
"jpeg_restart" - if set to a plain integer "N", generate a JPEG restart marker every "N" rows, if set
to an integer followed by "B", generate a JPEG restart marker every "N" MCUs, the 8x8 pixel blocks
that make up a JPEG image. Note that if this is specified in rows it will be translated to MCUs by
"libjpeg".
This allows a decoder to recover from corruption, but it makes the file slightly larger.
Default: 0, no restart markers are produced.
•
"jpeg_sample" - control subsampling of the YCbCr components, equivalent to the "-sample" parameter
for "cjpeg".
Default: "2x2,1x1,1x1", default 4:2:0 JPEG subsampling.
The following options can be set on writing with "MozJPEG" and correspond directly to the API options
described in the "MozJPEG" README-mozilla.txt. Attempting to set them when Imager::File::JPEG has been
built with another "libjpeg" will result in an error.
• "jpeg_optimize_scans", "jpeg_trellis_quant", "jpeg_trellis_quant_dc", "jpeg_tresllis_eob_opt",
"jpeg_use_lambda_weight_tbl", "jpeg_use_scans_in_trellis", "jpeg_overshoot_deringing" - boolean
options, set to 0 or 1.
"jpeg_lambda_log_scale1", "jpeg_lambda_log_scale2", "jpeg_trellis_delta_dc_weight" - integer options.
"jpeg_trellis_freq_split", "jpeg_trellis_num_loops", "jpeg_base_quant_tbl_idx",
"jpeg_dc_scan_opt_mode" - floating point options.
When reading a JPEG image, the following tag will be set, and ignored on writing:
• "jpeg_read_arithmetic" - the image had been written with arithmetic coding. This uses a separate
name from writing to avoid arithmetic coding from being accidentally propagated to a file that might
need to be read by an implementation without arithmetic coding support.
If an "APP1" block containing EXIF information is found, then any of the following tags can be set when
reading a JPEG image:
exif_aperture exif_artist exif_brightness exif_color_space exif_contrast exif_copyright
exif_custom_rendered exif_date_time exif_date_time_digitized exif_date_time_original
exif_digital_zoom_ratio exif_exposure_bias exif_exposure_index exif_exposure_mode
exif_exposure_program exif_exposure_time exif_f_number exif_flash exif_flash_energy
exif_flashpix_version exif_focal_length exif_focal_length_in_35mm_film
exif_focal_plane_resolution_unit exif_focal_plane_x_resolution exif_focal_plane_y_resolution
exif_gain_control exif_image_description exif_image_unique_id exif_iso_speed_rating exif_make
exif_max_aperture exif_metering_mode exif_model exif_orientation exif_related_sound_file
exif_resolution_unit exif_saturation exif_scene_capture_type exif_sensing_method exif_sharpness
exif_shutter_speed exif_software exif_spectral_sensitivity exif_sub_sec_time
exif_sub_sec_time_digitized exif_sub_sec_time_original exif_subject_distance
exif_subject_distance_range exif_subject_location exif_tag_light_source exif_user_comment
exif_version exif_white_balance exif_x_resolution exif_y_resolution
The following derived tags can also be set when reading a JPEG image:
exif_color_space_name exif_contrast_name exif_custom_rendered_name exif_exposure_mode_name
exif_exposure_program_name exif_flash_name exif_focal_plane_resolution_unit_name
exif_gain_control_name exif_light_source_name exif_metering_mode_name exif_resolution_unit_name
exif_saturation_name exif_scene_capture_type_name exif_sensing_method_name exif_sharpness_name
exif_subject_distance_range_name exif_white_balance_name
The derived tags are for enumerated fields, when the value for the base field is valid then the text that
appears in the EXIF specification for that value appears in the derived field. So for example if
"exf_metering_mode" is 5 then "exif_metering_mode_name" is set to "Pattern".
eg.
my $image = Imager->new;
$image->read(file => 'exiftest.jpg')
or die "Cannot load image: ", $image->errstr;
print $image->tags(name => "exif_image_description"), "\n";
print $image->tags(name => "exif_exposure_mode"), "\n";
print $image->tags(name => "exif_exposure_mode_name"), "\n";
# for the exiftest.jpg in the Imager distribution the output would be:
Imager Development Notes
0
Auto exposure
Imager will not write EXIF tags to any type of image, if you need more advanced EXIF handling, consider
Image::ExifTool.
parseiptc()
Historically, Imager saves IPTC data when reading a JPEG image, the parseiptc() method returns a list
of key/value pairs resulting from a simple decoding of that data.
Any future IPTC data decoding is likely to go into tags.
GIF
When writing one of more GIF images you can use the same Quantization Options as you can when converting
an RGB image into a paletted image.
When reading a GIF all of the sub-images are combined using the screen size and image positions into one
big image, producing an RGB image. This may change in the future to produce a paletted image where
possible.
When you read a single GIF with "$img->read()" you can supply a reference to a scalar in the "colors"
parameter, if the image is read the scalar will be filled with a reference to an anonymous array of
Imager::Color objects, representing the palette of the image. This will be the first palette found in
the image. If you want the palettes for each of the images in the file, use read_multi() and use the
getcolors() method on each image.
GIF does not support the spatial resolution tags.
Imager will set the following tags in each image when reading, and can use most of them when writing to
GIF:
• gif_left - the offset of the image from the left of the "screen" ("Image Left Position")
• gif_top - the offset of the image from the top of the "screen" ("Image Top Position")
• gif_interlace - non-zero if the image was interlaced ("Interlace Flag")
• gif_screen_width, gif_screen_height - the size of the logical screen. When writing this is used as
the minimum. If any image being written would extend beyond this then the screen size is extended.
("Logical Screen Width", "Logical Screen Height").
• gif_local_map - Non-zero if this image had a local color map. If set for an image when writing the
image is quantized separately from the other images in the file.
• gif_background - The index in the global color map of the logical screen's background color. This is
only set if the current image uses the global color map. You can set this on write too, but for it
to choose the color you want, you will need to supply only paletted images and set the
"gif_eliminate_unused" tag to 0.
• gif_trans_index - The index of the color in the color map used for transparency. If the image has a
transparency then it is returned as a 4 channel image with the alpha set to zero in this palette
entry. This value is not used when writing. ("Transparent Color Index")
• gif_trans_color - A reference to an Imager::Color object, which is the color to use for the palette
entry used to represent transparency in the palette. You need to set the "transp" option (see
"Quantization options" in Imager::ImageTypes) for this value to be used.
• gif_delay - The delay until the next frame is displayed, in 1/100 of a second. ("Delay Time").
• gif_user_input - whether or not a user input is expected before continuing (view dependent) ("User
Input Flag").
• gif_disposal - how the next frame is displayed ("Disposal Method")
• gif_loop - the number of loops from the Netscape Loop extension. This may be zero to loop forever.
• gif_comment - the first block of the first GIF comment before each image.
• gif_eliminate_unused - If this is true, when you write a paletted image any unused colors will be
eliminated from its palette. This is set by default.
• gif_colormap_size - the original size of the color map for the image. The color map of the image may
have been expanded to include out of range color indexes.
Where applicable, the ("name") is the name of that field from the "GIF89" standard.
The following GIF writing options are obsolete, you should set the corresponding tag in the image, either
by using the tags functions, or by supplying the tag and value as options.
• gif_each_palette - Each image in the GIF file has it's own palette if this is non-zero. All but the
first image has a local color table (the first uses the global color table.
Use "gif_local_map" in new code.
• interlace - The images are written interlaced if this is non-zero.
Use "gif_interlace" in new code.
• gif_delays - A reference to an array containing the delays between images, in 1/100 seconds.
Use "gif_delay" in new code.
• gif_positions - A reference to an array of references to arrays which represent screen positions for
each image.
New code should use the "gif_left" and "gif_top" tags.
• gif_loop_count - If this is non-zero the Netscape loop extension block is generated, which makes the
animation of the images repeat.
This is currently unimplemented due to some limitations in "giflib".
You can supply a "page" parameter to the read() method to read some page other than the first. The page
is 0 based:
# read the second image in the file
$image->read(file=>"example.gif", page=>1)
or die "Cannot read second page: ",$image->errstr,"\n";
Before release 0.46, Imager would read multiple image GIF image files into a single image, overlaying
each of the images onto the virtual GIF screen.
As of 0.46 the default is to read the first image from the file, as if called with "page => 0".
You can return to the previous behavior by calling read with the "gif_consolidate" parameter set to a
true value:
$img->read(file=>$some_gif_file, gif_consolidate=>1);
As with the to_paletted() method, if you supply a colors parameter as a reference to an array, this will
be filled with Imager::Color objects of the color table generated for the image file.
TIFF(TaggedImageFileFormat)
Imager can write images to either paletted or RGB TIFF images, depending on the type of the source image.
When writing direct color images to TIFF the sample size of the output file depends on the input:
• double/sample - written as 32-bit/sample TIFF
• 16-bit/sample - written as 16-bit/sample TIFF
• 8-bit/sample - written as 8-bit/sample TIFF
For paletted images:
• "$img->is_bilevel" is true - the image is written as bi-level
• otherwise - image is written as paletted.
If you are creating images for faxing you can set the class parameter set to "fax". By default the image
is written in fine mode, but this can be overridden by setting the fax_fine parameter to zero. Since a
fax image is bi-level, Imager uses a threshold to decide if a given pixel is black or white, based on a
single channel. For gray scale images channel 0 is used, for color images channel 1 (green) is used. If
you want more control over the conversion you can use $img->to_paletted() to product a bi-level image.
This way you can use dithering:
my $bilevel = $img->to_paletted(make_colors => 'mono',
translate => 'errdiff',
errdiff => 'stucki');
• "class" - If set to 'fax' the image will be written as a bi-level fax image.
• "fax_fine" - By default when "class" is set to 'fax' the image is written in fine mode, you can
select normal mode by setting "fax_fine" to 0.
Imager should be able to read any TIFF image you supply. Paletted TIFF images are read as paletted
Imager images, since paletted TIFF images have 16-bits/sample (48-bits/color) this means the bottom
8-bits are lost, but this shouldn't be a big deal.
TIFF supports the spatial resolution tags. See the "tiff_resolutionunit" tag for some extra options.
As of Imager 0.62 Imager reads:
• 8-bit/sample gray, RGB or CMYK images, including a possible alpha channel as an 8-bit/sample image.
• 16-bit gray, RGB, or CMYK image, including a possible alpha channel as a 16-bit/sample image.
• 32-bit gray, RGB image, including a possible alpha channel as a double/sample image.
• bi-level images as paletted images containing only black and white, which other formats will also
write as bi-level.
• tiled paletted images are now handled correctly
• other images are read using "tifflib"'s RGBA interface as 8-bit/sample images.
The following tags are set in a TIFF image when read, and can be set to control output:
• "tiff_compression" - When reading an image this is set to the numeric value of the TIFF compression
tag.
On writing you can set this to either a numeric compression tag value, or one of the following
values:
Ident Number Description
none 1 No compression
packbits 32773 Macintosh RLE
ccittrle 2 CCITT RLE
fax3 3 CCITT Group 3 fax encoding (T.4)
t4 3 As above
fax4 4 CCITT Group 4 fax encoding (T.6)
t6 4 As above
lzw 5 LZW
jpeg 7 JPEG
zip 8 Deflate (GZIP) Non-standard
deflate 8 As above.
oldzip 32946 Deflate with an older code.
ccittrlew 32771 Word aligned CCITT RLE
In general a compression setting will be ignored where it doesn't make sense, eg. "jpeg" will be
ignored for compression if the image is being written as bilevel.
Imager attempts to check that your build of "libtiff" supports the given compression, and will
fallback to "packbits" if it isn't enabled. eg. older distributions didn't include LZW compression,
and JPEG compression is only available if "libtiff" is configured with "libjpeg"'s location.
$im->write(file => 'foo.tif', tiff_compression => 'lzw')
or die $im->errstr;
• "tags, tiff_jpegquality""tiff_jpegquality" - If "tiff_compression" is "jpeg" then this can be a
number from 1 to 100 giving the JPEG compression quality. High values are better quality and larger
files.
•
"tiff_resolutionunit" - The value of the "ResolutionUnit" tag. This is ignored on writing if the
i_aspect_only tag is non-zero.
The "i_xres" and "i_yres" tags are expressed in pixels per inch no matter the value of this tag, they
will be converted to/from the value stored in the TIFF file.
•
"tiff_resolutionunit_name" - This is set when reading a TIFF file to the name of the unit given by
"tiff_resolutionunit". Possible results include "inch", "centimeter", "none" (the "i_aspect_only"
tag is also set reading these files) or "unknown".
•
"tiff_bitspersample" - Bits per sample from the image. This value is not used when writing an
image, it is only set on a read image.
•
"tiff_photometric" - Value of the "PhotometricInterpretation" tag from the image. This value is not
used when writing an image, it is only set on a read image.
• "tiff_documentname", "tiff_imagedescription", "tiff_make", "tiff_model", "tiff_pagename",
"tiff_software", "tiff_datetime", "tiff_artist", "tiff_hostcomputer" - Various strings describing the
image. "tiff_datetime" must be formatted as "YYYY:MM:DD HH:MM:SS". These correspond directly to the
mixed case names in the TIFF specification. These are set in images read from a TIFF and saved when
writing a TIFF image.
You can supply a "page" parameter to the read() method to read some page other than the first. The page
is 0 based:
# read the second image in the file
$image->read(file=>"example.tif", page=>1)
or die "Cannot read second page: ",$image->errstr,"\n";
If you read an image with multiple alpha channels, then only the first alpha channel will be read.
When reading a "TIFF" image with callbacks, the "seekcb" callback parameter is also required.
When writing a "TIFF" image with callbacks, the "seekcb" and "readcb" parameters are also required.
"TIFF" is a random access file format, it cannot be read from or written to unseekable streams such as
pipes or sockets.
BMP(WindowsBitmap)
Imager can write 24-bit RGB, and 8, 4 and 1-bit per pixel paletted Windows BMP files. Currently you
cannot write compressed BMP files with Imager.
Imager can read 24-bit RGB, and 8, 4 and 1-bit perl pixel paletted Windows BMP files. There is some
support for reading 16-bit per pixel images, but I haven't found any for testing.
BMP has no support for multiple image files.
BMP files support the spatial resolution tags, but since BMP has no support for storing only an aspect
ratio, if "i_aspect_only" is set when you write the "i_xres" and "i_yres" values are scaled so the
smaller is 72 DPI.
The following tags are set when you read an image from a BMP file:
bmp_compression
The type of compression, if any. This can be any of the following values:
BI_RGB (0)
Uncompressed.
BI_RLE8 (1)
8-bits/pixel paletted value RLE compression.
BI_RLE4 (2)
4-bits/pixel paletted value RLE compression.
BI_BITFIELDS (3)
Packed RGB values.
bmp_compression_name
The bmp_compression value as a BI_* string
bmp_important_colors
The number of important colors as defined by the writer of the image.
bmp_used_colors
Number of color used from the BMP header
bmp_filesize
The file size from the BMP header
bmp_bit_count
Number of bits stored per pixel. (24, 8, 4 or 1)
TGA(Targa)
When storing Targa images RLE compression can be activated with the "compress" parameter, the "idstring"
parameter can be used to set the Targa comment field and the "wierdpack" option can be used to use the 15
and 16 bit Targa formats for RGB and RGBA data. The 15 bit format has 5 of each red, green and blue.
The 16 bit format in addition allows 1 bit of alpha. The most significant bits are used for each
channel.
Tags:
tga_idstring
tga_bitspp
compressed
RAW
When reading raw images you need to supply the width and height of the image in the "xsize" and "ysize"
options:
$img->read(file=>'foo.raw', xsize=>100, ysize=>100)
or die "Cannot read raw image\n";
If your input file has more channels than you want, or (as is common), junk in the fourth channel, you
can use the "raw_datachannels" and "raw_storechannels" options to control the number of channels in your
input file and the resulting channels in your image. For example, if your input image uses 32-bits per
pixel with red, green, blue and junk values for each pixel you could do:
$img->read(file=>'foo.raw', xsize => 100, ysize => 100,
raw_datachannels => 4, raw_storechannels => 3,
raw_interleave => 0)
or die "Cannot read raw image\n";
In general, if you supply "raw_storechannels" you should also supply "raw_datachannels"
Read parameters:
• "raw_interleave" - controls the ordering of samples within the image. Default: 1. Alternatively and
historically spelled "interleave". Possible values:
• 0 - samples are pixel by pixel, so all samples for the first pixel, then all samples for the
second pixel and so on. eg. for a four pixel scan line the channels would be laid out as:
012012012012
• 1 - samples are line by line, so channel 0 for the entire scan line is followed by channel 1 for
the entire scan line and so on. eg. for a four pixel scan line the channels would be laid out
as:
000011112222
This is the default.
Unfortunately, historically, the default "raw_interleave" for read has been 1, while writing only
supports the "raw_interleave" = 0 format.
For future compatibility, you should always supply the "raw_interleave" (or "interleave") parameter.
As of 0.68, Imager will warn if you attempt to read a raw image without a "raw_interleave" parameter.
• "raw_storechannels" - the number of channels to store in the image. Range: 1 to 4. Default: 3.
Alternatively and historically spelled "storechannels".
• "raw_datachannels" - the number of channels to read from the file. Range: 1 or more. Default: 3.
Alternatively and historically spelled "datachannels".
$img->read(file=>'foo.raw', xsize=100, ysize=>100, raw_interleave=>1)
or die "Cannot read raw image\n";
PNGPNGImagemodes
PNG files can be read and written in the following modes:
• bi-level - written as a 1-bit per sample gray scale image
• paletted - Imager gray scale paletted images are written as RGB paletted images. PNG palettes can
include alpha values for each entry and this is honored as an Imager four channel paletted image.
• 8 and 16-bit per sample gray scale, optionally with an alpha channel.
• 8 and 16-bit per sample RGB, optionally with an alpha channel.
Unlike GIF, there is no automatic conversion to a paletted image, since PNG supports direct color.
PNGTexttags
Text tags are retrieved from and written to PNG "tEXT" or "zTXT" chunks. The following standard tags
from the PNG specification are directly supported:
• "i_comment" - keyword of "Comment".
• "png_author" - keyword "Author".
• "png_copyright" - keyword "Copyright".
• "png_creation_time" - keyword "Creation Time".
• "png_description" - keyword "Description".
• "png_disclaimer" - keyword "Disclaimer".
• "png_software" - keyword "Software".
• "png_title" - keyword "Title".
• "png_warning" - keyword "Warning".
Each of these tags has a corresponding "base-tag-name_compressed" tag, eg. "png_comment_compressed".
When reading, if the PNG chunk is compressed this tag will be set to 1, but is otherwise unset. When
writing, Imager will honor the compression tag if set and non-zero, otherwise the chunk text will be
compressed if the value is longer than 1000 characters, as recommended by the "libpng" documentation.
PNG "tEXT" or "zTXT" chunks outside of those above are read into or written from Imager tags named like:
• "png_textN_key" - the key for the text chunk. This can be 1 to 79 characters, may not contain any
leading, trailing or consecutive spaces, and may contain only Latin-1 characters from 32-126,
161-255.
• "png_textN_text" - the text for the text chunk. This may not contain any "NUL" characters.
• "png_textN_compressed" - whether or not the text chunk is compressed. This behaves similarly to the
"base-tag-name_compressed" tags described above.
Where N starts from 0. When writing both the "..._key" and "..._text" tags must be present or the write
will fail. If the key or text do not satisfy the requirements above the write will fail.
OtherPNGmetadatatags
•
"png_interlace", "png_interlace_name" - only set when reading, "png_interlace" is set to the type of
interlacing used by the file, 0 for one, 1 for Adam7. "png_interlace_name" is set to a keyword
describing the interlacing, either "none" or "adam7".
•
"png_srgb_intent" - the sRGB rendering intent for the image. an integer from 0 to 3, per the PNG
specification. If this chunk is found in the PNG file the "gAMA" and "cHRM" are ignored and the
"png_gamma" and "png_chroma_..." tags are not set. Similarly when writing if "png_srgb_intent" is
set the "gAMA" and "cHRM" chunks are not written.
•
"png_gamma" - the gamma of the image. This value is not currently used by Imager when processing the
image, but this may change in the future.
•
"png_chroma_white_x", "png_chroma_white_y", "png_chroma_red_x", "png_chroma_red_y",
"png_chroma_green_x", "png_chroma_green_y", "png_chroma_blue_x", "png_chroma_blue_y" - the primary
chromaticities of the image, defining the color model. This is currently not used by Imager when
processing the image, but this may change in the future.
• "i_xres", "i_yres", "i_aspect_only" - processed per Imager::ImageTypes/CommonTags.
•
"png_bits" - the number of bits per sample in the representation. Ignored when writing.
•
"png_time" - the creation time of the file formatted as "year-month-dayThour:minute:second". This
is stored as time data structure in the file, not a string. If you set "png_time" and it cannot be
parsed as above, writing the PNG file will fail.
• "i_background" - set from the "sBKG" when reading an image file.
You can control the level of zlib compression used when writing with the "png_compression_level"
parameter. This can be an integer between 0 (uncompressed) and 9 (best compression).
If you're using libpng 1.6 or later, or an earlier release configured with
"PNG_BENIGN_ERRORS_SUPPORTED", you can choose to ignore file format errors the authors of libpng consider
benign, this includes at least CRC errors and palette index overflows. Do this by supplying a true value
for the "png_ignore_benign_errors" parameter to the read() method:
$im->read(file => "foo.png", png_ignore_benign_errors => 1)
or die $im->errstr;
ICO(MicrosoftWindowsIcon)andCUR(MicrosoftWindowsCursor)
Icon and Cursor files are very similar, the only differences being a number in the header and the storage
of the cursor hot spot. I've treated them separately so that you're not messing with tags to distinguish
between them.
The following tags are set when reading an icon image and are used when writing it:
ico_mask
This is the AND mask of the icon. When used as an icon in Windows 1 bits in the mask correspond to
pixels that are modified by the source image rather than simply replaced by the source image.
Rather than requiring a binary bitmap this is accepted in a specific format:
• first line consisting of the 0 placeholder, the 1 placeholder and a newline.
• following lines which contain 0 and 1 placeholders for each scan line of the image, starting from
the top of the image.
When reading an image, '.' is used as the 0 placeholder and '*' as the 1 placeholder. An example:
.*
..........................******
..........................******
..........................******
..........................******
...........................*****
............................****
............................****
.............................***
.............................***
.............................***
.............................***
..............................**
..............................**
...............................*
...............................*
................................
................................
................................
................................
................................
................................
*...............................
**..............................
**..............................
***.............................
***.............................
****............................
****............................
*****...........................
*****...........................
*****...........................
*****...........................
The following tags are set when reading an icon:
ico_bits
The number of bits per pixel used to store the image.
For cursor files the following tags are set and read when reading and writing:
cur_mask
This is the same as the ico_mask above.
cur_hotspotx
cur_hotspoty
The "hot" spot of the cursor image. This is the spot on the cursor that you click with. If you set
these to out of range values they are clipped to the size of the image when written to the file.
The following parameters can be supplied to read() or read_multi() to control reading of ICO/CUR files:
• "ico_masked" - if true, the default, then the icon/cursors mask is applied as an alpha channel to the
image, unless that image already has an alpha channel. This may result in a paletted image being
returned as a direct color image. Default: 1
# retrieve the image as stored, without using the mask as an alpha
# channel
$img->read(file => 'foo.ico', ico_masked => 0)
or die $img->errstr;
This was introduced in Imager 0.60. Previously reading ICO images acted as if "ico_masked => 0".
• "ico_alpha_masked" - if true, then the icon/cursor mask is applied as an alpha channel to images that
already have an alpha mask. Note that this will only make pixels transparent, not opaque. Default:
0.
Note: If you get different results between "ico_alpha_masked" being set to 0 and 1, your mask may
break when used with the Win32 API.
"cur_bits" is set when reading a cursor.
Examples:
my $img = Imager->new(xsize => 32, ysize => 32, channels => 4);
$im->box(color => 'FF0000');
$im->write(file => 'box.ico');
$im->settag(name => 'cur_hotspotx', value => 16);
$im->settag(name => 'cur_hotspoty', value => 16);
$im->write(file => 'box.cur');
SGI(RGB,BW)
SGI images, often called by the extensions, RGB or BW, can be stored either uncompressed or compressed
using an RLE compression.
By default, when saving to an extension of "rgb", "bw", "sgi", "rgba" the file will be saved in SGI
format. The file extension is otherwise ignored, so saving a 3-channel image to a ".bw" file will result
in a 3-channel image on disk.
The following tags are set when reading a SGI image:
• i_comment - the "IMAGENAME" field from the image. Also written to the file when writing.
• sgi_pixmin, sgi_pixmax - the "PIXMIN" and "PIXMAX" fields from the image. On reading image data is
expanded from this range to the full range of samples in the image.
• sgi_bpc - the number of bytes per sample for the image. Ignored when writing.
• sgi_rle - whether or not the image is compressed. If this is non-zero when writing the image will be
compressed.