pod::Pr...ge-load(3)
πΈ NAME πΈ
Prima::image-load β using the image subsystem π
okay so real talk, bestie: this whole page lives at pod::Prima::image-load(3) and it's from the User Contributed Perl Documentation, and it's literally your glow-up guide to driving the Prima image subsystem around. no cap. π«Ά
β¨ DESCRIPTION β¨
This document describes using the Prima image subsystem for loading and saving images. that's the whole vibe β we're moving pictures in and out of Prima and looking cute doing it. π
π§ Loading π§
π Simple loading
In the simplest case, loading a single image would look like this:
my $x = Prima::Image-> load( 'filename.jpg');
die "$@" unless $x;
Image functions can be invoked either as package functions or as Prima::Image object methods. so the code above could be also written as:
my $x = Prima::Image-> new;
die "$@" unless $x-> load( 'filename.jpg');
In both cases, $x contains loaded image data upon success. If an error occurs, it is returned in the $@ variable (see perlvar). not me checking $@ every single time, but likeβ¦ do it. π
π Loading from stream
Prima::Image can also load images by reading from a stream:
open FILE, 'a.jpeg' or die "Cannot open:$!";
binmode FILE;
my $x = Prima::Image-> load( \*FILE);
die "$@" unless $x;
π¦ Multiframe loading
Multiframe load calls can be issued in two ways:
my @x = Prima::Image-> load( 'filename.gif', loadAll => 1);
die "$@" unless $x[-1];
my $x = Prima::Image-> new;
my @x = $x-> load( 'filename.gif', loadAll => 1);
die "$@" unless $x[-1];
In the second case, the content of the first frame is stored in $x and $x[0]. To check if the error has occurred during the loading, inspect the last item of the returned array; it is undefined if the error indeed occurred. This check works also if an empty array is returned. Only this last item can be undefined, others are guaranteed to be valid objects. so like, peek at the last one only, bestie, the rest are trusted. π
Prima can load more than one image from a file, assuming the image format allows that. The "load" function recognizes such multiframe semantics when certain extra hash keys are used. These keys are:
loadAllβ Requests to load all frames that can be read from the file:
loadAll => 1
indexβ If present, returns a single frame with the index given:
index => 8
mapβ Contains an anonymous array of the frame indices to load. The indices must be integers that are greater or equal to zero:
map => [0, 10, 15..20]
π Querying extra information
By default, Prima loads only image pixels and palette. For any other information that can be loaded, use the hash 'extras' bound to the image object. To notify the image loader that this extra information is expected, the "loadExtras" boolean value is used:
my $x = Prima::Image-> load( $f, loadExtras => 1);
die "$@" unless $x;
for ( keys %{$x-> {extras}}) {
print " $_ : $x->{extras}->{$_}\n";
}
The code above loads and prints extra information read from a file. Typical output, for example, from a gif codec based on the libgif library would look like this:
codecID : 1
transparentColorIndex : 1
comment : created by GIMP
frames : 18
"codecID" is a Prima-defined integer field, an internal index of the codec which had previously loaded the file. This value is useful for the explicit selection of the codec to be used for saving an image. iykyk. π―
"frames" is also a Prima-defined field, with its integer value set to the number of frames in the image. It might be set to -1 signaling that the codec is incapable of quick reading of the frame count. If, however, it is necessary to get the actual frame count, the "wantFrames" boolean value should be set to 1 β then the "frames" field is guaranteed to be set to a 0 or a positive value. Such a request may take longer though, especially on large files with sequential access. A real-life example is a gif file with more than a thousand frames. The "wantFrames" flag is also useful in null load requests (see below). consider yourself warned, it's giving "patience is a virtue" energy. π
π«Ά Multiprofile loading requests
The parameters that are accepted by the "load" function are divided into two groups β first, those that apply to the whole loading process, and then those that apply only to a particular frame. Some fields that were already mentioned ("wantFrames" and "loadAll") belong to the first group because they affect the whole loading session. Some other parameters ("loadExtras", "noImageData", "noIncomplete", "iconUnmask") can be applied to each loaded frame, individually. A codec may as well define its own parameters, however, it is not possible to tell what parameter belongs to what group β this information is to be found in the codec documentation. (go read the codec docs, bestie, they told me to tell you.) π
The parameters that apply to a frame, can be specified separately for every frame in a single call. For that purpose, the special parameter "profiles" is defined. The "profiles" value is expected to be an anonymous array of hashes, where each hash corresponds to a request number. For example:
$x-> load( $f, loadAll => 1, profiles => [
{loadExtras => 0},
{loadExtras => 1},
]);
The first hash there applies to the frame index 0, second β to the frame index 1. Note that in the code below
$x-> load( $f,
map => [ 5, 10],
profiles => [
{loadExtras => 0},
{loadExtras => 1},
]);
first hash applies to the frame index 5, and second β to the frame index 10. cute how that works, right?? π
π Null load requests
If it is desired to quickly peek into an image, reading only its pixel type and dimensions, one should set the "noImageData" boolean value to 1. Using "noImageData", empty image objects are returned, that would have the "type" property set to the image type (as the codec would translate it to the Prima image type), and with the extras "width" and "height" set to the image dimensions. Example:
$x-> load( $f, noImageData => 1);
die "$@" unless $x;
print $x-> {extras}-> {width} , 'x' , $x-> {extras}-> {height}, 'x',
$x-> type & im::BPP, "\n";
Some image information can be loaded even without frame loading β if the codec provides such a functionality. This is the only request that cannot be issued with the package syntax, an existing image object is required:
my $x = Prima::Image->new;
$x-> load( $f, map => [], loadExtras => 1);
Since no frames are required to load, an empty array is returned on success and an array with one undefined value on failure. yes, empty array = slay, undefined value = not slay. β
π Using Prima::Image descendants
If Prima needs to create a storage object, it uses by default either the class name of the caller object, or the package the request was issued on, or the "Prima::Image" class. This behavior can be altered using the parameter "className", which defines the class to be used for each frame:
my @x = Prima::Image-> load( $f,
map => [ 1..3],
className => 'Prima::Icon',
profiles => [
{},
{ className => 'Prima::Image' },
{}
],
In this example, @x will contain (Icon, Image, Icon) upon success. main character lineup fr fr. π
When loading to an Icon object, the default toolkit action is to build the transparency mask based on the image data. When this is not desired, f.ex., there is no explicit knowledge of the image to be loaded, while the image may or may not contain transparency information, the "iconUnmask" boolean parameter can be used. When set to the "true" value, and the object is a "Prima::Icon" descendant, "Prima::Icon::autoMasking" is set to "am::None" before the file loading which effectively disables any attempt to generate the icon mask. By default, this option is turned off.
πΈ Loading with the progress indicator
Some codecs (PNG,TIFF,JPEG) can signal their progress as they read image data. For this purpose, the "Prima::Image" class defines two events, "onHeaderReady" and "onDataReady". If either (or both) are present on the image object issuing the "load" call, and the codec supports progressive loading, then these events will be called. The "onHeaderReady" event is called when the image header data is acquired, and an empty image with the required pixel dimensions and type is allocated. The "onDataReady" notification is called whenever a part of the image is ready and is loaded in the memory of the object; the position and dimensions of the loaded area are reported also. The format of the events is as follows:
onHeaderReady $OBJECT
onDataReady $OBJECT, $X, $Y, $WIDTH, $HEIGHT
The "onHeaderReady" event is called only once while "onDataReady" is called as soon as new image data is available. To reduce the frequency of these calls, which otherwise would be issued after every scanline loaded, "load" has the parameter "eventDelay", the minimum number of seconds that need to pass between two consecutive "onDataReady" calls. The default "eventDelay" is 0.1 . β±οΈ
The handling of the "onDataReady" event must be performed with care. First, the image must be accessed read-only, i e no transformations of any kind are allowed. Currently, there is no protection for such actions ( because the codec must also perform these itself), so a crash will most surely issue. Second, loading and saving of images is not in general reentrant, and although some codecs are reentrant, loading and saving images inside image events is not recommended.
like seriously bestie, read that box twice. no touching, no saving, no transforming. we are NOT crashing today. ππ
There are two techniques to display the image progressively. Both of them require overloading the "onHeaderReady" and "onDataReady" callbacks. The simpler case is to call the "put_image" method from inside "onDataReady":
$i = Prima::Image-> new(
onDataReady => sub {
$progress_widget-> put_image( 0, 0, $i);
},
);
but that will most probably load heavily underlying OS-dependent conversion of the image data to native display bitmap data. A smarter, but more complex solution is to copy loaded (and only loaded) bits to a preexisting bitmap or image:
$i = Prima::Image-> new(
onHeaderReady => sub {
$bitmap = Prima::DeviceBitmap-> new(
width => $i-> width,
height => $i-> height,
));
},
onDataReady => sub {
my ( $i, $x, $y, $w, $h) = @_;
$bitmap-> put_image( $x, $y, $i-> extract( $x, $y, $w, $h));
},
);
The latter technique is used by the "Prima::ImageViewer" widget class when it is ordered to monitor the image loading progress. See "watch_load_progress" in Prima::ImageViewer for details. π¦
Truncated files
okay so by default, codecs get zero heads-up about whether they'd fail on a premature end of file or just quietly skip the error and hand you back a truncated image π« . The noIncomplete boolean parameter is the fix: it tells the codec "bestie, you MUST always fail if the image can't be read in full." It's off by default. And if the codec does catch that the file is incomplete, it sets the truncated field in the extras profile β but only if loadExtras was requested. That field is a string, and it contains the error message that occurred when the codec tried to load the truncated field. iykyk π
Inline files
Using the Prima::Image::base64 module it is possible to convert images into base64 and embed the result directly into the source code. Assuming an appropriate codec was compiled in, the following would work:
my $icon = Prima::Icon->load_stream(<<~'ICON');
R0lGODdhIAAgAIAAAAAAAP///ywAAAAAIAAgAIAAAAD///8CT4SPqcvtD6OctNqLcwogcK91nEhq
3gim2Umm4+W2IBzX0fvl8jTr9SeZiU5E4a1XLHZ4yaal6XwFoSwMVUVzhoZSaQW6ZXjD5LL5jE6r
DQUAOw==
ICON
print $icon->save_stream;
Reading one frame at a time
When you need to load <italics>all</italics> the frames from an image that contains, like, way too many frames, or you're under a memory constraint, Prima provides a way to load images one by one β no need to allocate space for every single frame in the file π₯.
This section describes the lower-level API that allows for that functionality, however, an easier-to-use higher level API is documented in Prima::Image::Loader.
So to read one frame at a time, the programmer opens a loading session by adding the session => 1 option to the load call. Heads up: that call can only be made on an existing object, not on the package π. The call returns the success flag and an eventual error in $@, as usual. No frames are loaded yet, though the extras hash on the caller image object may be filled, depending on the loadExtras option. The options supplied to the session-opening call apply to all subsequent frames, but these settings may be overridden later.
Having the session successfully opened, the subsequent calls to load with the session => 1 option β but with the first parameter set to undef β will load the next frame. Each of those load calls will recognize the options supplied and apply them to individual frames. Session-based loading recognizes all of the function options, except the map, profiles and loadAll options π«. The loading session closes automatically after either a first loading failure or after the end of file is reached. iconic behavior honestly β¨
πΎ SAVING πΎ
Simple saving
The typical saving code is
$x-> save( 'filename.jpg') or die $@;
The function returns 1 on success and 0 on failure. Save requests also can be performed with the package syntax:
die "$@" unless Prima::Image-> save( 'filename.jpg',
images => [$x]);
Saving to a stream
Saving to a stream requires the explicit codecID integer value to be supplied. When the image is loaded with loadExtras, this field is always present on the image object and is the integer that selects the image file format π
my ($png_id) =
map { $_-> {codecID} }
grep { $_-> {fileShortType} =~ /^png$/i }
@{ Prima::Image-> codecs };
die "No png codec installed" unless $png_id;
open FILE, ">", "a.png" or die "Cannot save:$!";
binmode FILE;
$image-> save( \*FILE, codecID => $png_id)
or die "Cannot save:$@";
Multiframe saving
When saving more than one image object into a single file, the method returns the number of successfully saved frames. Careful though π¨ β the saved image file is erased if an error occurs, even after some frames were successfully written. no cap.
die "$@" if scalar(@images) > Prima::Image-> save( $f,
images => \@images);
Saving extras information
All information found in the object hash reference extras is assumed to be saved in the image file too. It's a codec's own business how it reacts to invalid and/or unacceptable information β but a typical behavior is that keys the codec didn't recognize get ignored, while invalid values raise an error π
$x-> {extras}-> {comments} = 'Created by Prima';
$x-> save( $f);
Saving one frame at a time
Similar to session-based loading, Prima provides the functionality to save a multi-frame image one frame at a time, using similar API calls π¦
This section describes the lower-level API that allows for that functionality, however, an easier-to-use higher level API is documented in "Prima::Image::Saver" in Prima::Image::Loader.
In order to save one frame at a time, the programmer opens a saving session by adding the session => 1 option to the save call, plus the frames option that signals how many frames are to be saved in total. That call can only be made on an existing object, not on the package π. The call returns the success flag and an eventual error in $@, as usual. The options supplied to the session-opening call apply to all subsequent frames, but these settings may be overridden later.
Having the session successfully opened, the subsequent calls to save with session => 1 and the image as the first option will save the next frame. Each of those save calls will recognize the options supplied and will apply them to individual frames. Session-based saving recognizes all of the function options, except the images option. The saving session closes automatically after a first failure β¨
Selecting a codec
The integer field codecID β the same field that's defined after successful load requests β explicitly selects the codec for saving the image. If the codec is incapable of saving, then an error is returned. Selecting a codec is only possible with the object-driven syntax, and this information is never extracted from the objects but is passed in the images array instead π
$x-> {extras}-> {codecID} = 1;
$x-> save( $f);
The actual relation between codecs and their indices is described below.
Note: if codecID is not specified, Prima tries to deduce the codec by the file extension. iykyk π
Type conversion
Codecs usually are incapable of saving images in all possible pixel formats, so whenever Prima needs to save an image with an unsupported pixel type it either converts the image to an appropriate pixel format or signals an error. This behavior is managed by the parameter autoConvert, which is 1 by default.
- With
autoConvertset, it's guaranteed that the image will be saved β but original image information may be lost π - With the
autoConvertfield set to0, no information will be lost, but Prima may signal an error π
Therefore general-purpose saving routines should be planned carefully. As an example, the Prima::Dialog::ImageDialog::SaveImageDialog code might be useful.
When the conversion takes place, the Image property conversion is used for the selection of the error distribution algorithm if down-sampling is required πΈ
π MANAGING THE CODECS π
Prima provides the Prima::Image-> codecs function that returns an anonymous array of hashes, where every hash entry corresponds to a registered codec. The codecID parameter on load and save requests is the index in this array. Indexes for codecs registered once never change, so it's safe to manipulate these numbers within a single run of the program π₯
Codec information contained in these hashes contains the following fields:
codecIDβ a unique integer value for a codec, the same as the index of the codec entry in the result of thePrima::Image->codecsmethodnameβ the full codec name, stringvendorβ the codec vendor, stringversionMajorandversionMinorβ usually underlying library versions, integersfileExtensionsβ an array of strings, with file extensions that are typical to the codec. Example:['tif', 'tiff']fileTypeβ description of the type of file that the codec is designed to work with. A string.fileShortTypeβ short description of the type of file that the codec is designed to work with ( short means 3-4 characters ). A string.featuresSupportedβ an array of strings containing string description of the features that the codec supports β usually they implement only a part of the file format specification, so it's always interesting to know which part πmoduleandpackageβ specifies the perl module, usually inside thePrima/Imagedirectory in the Prima distribution, and the package name inside the module. The package contains some specific functions for working with codec-specific parameters. The current implementation defines the onlysave_dialogfunction that creates a dialog that allows changing these parameters. See"Prima::Dialog::ImageDialog::SaveImageDialog"for details. Strings orundef.canLoadβ1if the codec can load images,0if notcanLoadStreamβ1if the codec can load images from streams,0otherwisecanLoadMultipleβ1if the codec can handle multiframe load requests and load frames with an index more than zero,0otherwisecanSaveβ1if the codec can save images,0if not.canSaveStreamβ1if the codec can save images to streams,0otherwisecanSaveMultipleβ is set if the codec can save more than one frametypesβ an array of integers, each is a combination of theim::XXXflags, the image type that the codec can save. The first type in the list is the default type; if the type of the image to be saved is not in that list, the image will be converted to this default type.loadInputβ a hash, where the keys are those that are accepted by thePrima::Image-> loadmethod and the values are the default values for these keys.loadOutputβ an array of strings, each is the name of an extra information entry in theextrashash.saveInputβ a hash, where the keys are those that are accepted by thePrima::Image-> savemethod and the values are the default values for these keys.mimeβ an array of strings, containing the mime identifiers specific to the image format. An example:['image/xbm', 'image/x-bitmap']
β¨ API β¨
This section describes the parameters accepted and the data returned by the Prima::Image::load method π
Common
Loading parameters:
blending BOOLEAN = 1
Affects how to treat the alpha channel bits, if present π¦
alphaBOOL β okay so this one's the glow-up switch β¨ Set it and the alpha channel gets mixed with the background color when you're loading to an image, or the color bits (data or palette, both!) get premultiplied with alpha when you're loading to an icon. Heads up though: saving the object afterwards gives you different image pixel values, but the object is ready to be displayed immediately, no extra steps. Leave it unset and the color plus any eventual alpha bits (if loaded to an icon) stay untouched, zero changes. But then saving gives you the same image while the object is not ready to display right away. See also:premultiply_alphainPrima::Image.classNameSTRING β when you're loading more than one image, this string is what gets used to create the instances of image containers. Default is the calling class, i.e.Prima::ImageorPrima::Icon.eventDelayINT β sets the granularity of theonDataReadyevent in seconds, y'know, when the codec is actually capable of triggering it.
Default: 0.1
iconUnmaskBOOL β set it andPrima::Icon::autoMaskinggets set toam::Nonebefore the file loading happens, which disables literally any attempt to deduce mask pixels from the data pixels.
Default: false. Only actual for Prima::Icon loading.
indexINT β loading from a multiframe file? This picks which frame index you get.
Default: 0
loadExtrasBOOL β set it and all the available extra info goes into theextrashash on the loaded object. Little bonus bag π
Default: false
loadAllBOOL β multiframe file again, and this one selects that all frames are to be loaded. all of them. every single one π
Default: false
map[INT] β multiframe file, selects the set of frame indexes to load. Cherry-picking, we love it.
Default: undef
noImageDataBOOL β set it and neither image data is loaded nor image dimensions are changed (newly created images have a size of1x1, tiny legend behavior). Instead, the{extras}hash containswidthandheightintegers.
Default: false
noIncompleteBOOL β this controls what happens when the image is incomplete, truncated, etc. If it's set, it signals an error. Otherwise no error is signaled and whatever data could be recovered from the image is returned β in that case thetruncatedfield holds the error string.
Default: false
profiles[HASH] β an array of hashes passed down to each frame in multiframe loading sessions. Every frame loading request gets its own individual hash, which is the result of the hash join of all the profiles passed toImage::loadplus the *n*th hash in the array. very "everyone gets a party favor" of it π«ΆwantFramesBOOL β affects how the number of frames in a file gets reported in theframesfield. If set, Prima always scans the file for the exact number of frames. Otherwise it's up to the codec to do that (and sometimes it just won't, iykyk).
Default: false
See also: frames.
π« Load output
codecIDINT β indicates the internal codec ID used to load the image. Can be used forImage::save.framesINT β if set to a positive integer, indicates the number of frames in the file. Otherwise it signals that there are frames, but the codec needs an expensive scan to calculate the number (and thewantFramesparameter is set). π expensive scan, no thanksheightINT β when thenoImageDataparameter is set, contains the image height.truncatedBOOL β when thenoIncompleteparameter is set, will be set if the image was truncated. The value is the error string.widthINT β when thenoImageDataparameter is set, contains the image width.
ποΈ Saving parameters
autoConvertBOOL β controls what happens when the image can't be stored in a file in its existing pixel format. If set, the system tries to convert the image into one of the pixel formats supported by the selected codec. Otherwise it fails.
Default: true
codecIDINT β disables the whole algorithm where the codec is selected based on the filename extension. Uses the codec numbercodecIDinstead. Note that when saving images into streams this option must always be present β non-negotiable bestie, it's required.
Default: undef
π¨ BMP codec
BMP, the bitmap codec, is not dependent on external libraries and is always available. self-sufficient icon behavior, honestly π
BitDepthINT β original bit depth may differ fromImage::bpp.
Not valid as a saving parameter.
CompressionSTRING β bitmap compression method.
Not valid as a saving parameter.
HotSpotX,HotSpotYINT β if loading from a cursor file, contains the pointer hotspot coordinates.ImportantColorsINT β the minimal number of colors that is needed to display the image.OS2BOOL β is set when loading an OS/2 bitmap.XResolution,YResolutionINT β image resolution in PPM.
π₯οΈ X11 codec
X11, the X Consortium data file codec, is implemented internally and is always available. never not around π
hotSpotX,hotSpotYINT β contains the pointer hotspot coordinates, if any.
πΈ XPM codec
extensionsHASH β a set of xpm-specific extension strings. Cannot be used for saving.hintsComment,colorsComment,pixelsCommentSTRING β contains comments on different sections.hotSpotX,hotSpotYINT β contains the pointer hotspot coordinates.transparentColors[COLOR] β an array of transparent colors. Cannot be used for saving.
πΈ JPEG codec
Load parameters
exifTransformnone|auto|wipe β if set toautoorwipe, it tries to detect whether there are any exif tags hinting that the image has to be rotated and/or mirrored. If it finds any, it applies the transformation accordingly.
When set to wipe, in addition to that, it removes the exif tags so a subsequent image save won't give you transformed images with exif tags still present. clean slate, we love to see it π§Ό
This parameter requires a loadExtras parameter set, because exif tags are stored in extra JPEG data.
Output fields of the loader and input parameters for the saver
appdata[STRING] β an array of raw binary strings found in extra JPEG data.commentSTRING β any comment text found in the file.progressiveBOOL β if set, produces a progressively encoded JPEG file.
Default: 0
Only used for saving.
qualityINT β JPEG quality,1-100.
Default: 75
Only used for saving.
π¦ PNG codec
Load input
backgroundCOLOR β when a PNG file contains an alpha channel, andalphais set toblend, this color is used to blend the background. If set toclInvalid, the default PNG library background color is used.
Default: clInvalid
Not applicable to Prima::Icon.
gammaREAL β override the gamma value applied to the loaded image.
Default: 0.45455
screen_gammaREAL β current gamma value for the operating system, if specified.
Default: 2.2
Load output and save input
backgroundCOLOR β default PNG library background color.
Default: clInvalid, which means PNG library default.
blendMethodblend|no_blend|unknown β signals whether the new frame is to be blended over the existing animation, or whether it should replace that.delayTime$milliseconds β delay between frames.default_frameBOOLEAN β when set, means that the first image is the "default" frame, a special backward-compatibility image that is supposed to be excluded from the animation sequence, and only displayed when all animation frames cannot be loaded for whatever reason. the "just in case" frame πdisposalMethodnone|background|restore|unknown β signals whether the frame, before being replaced, is to be erased by the background color, or by the previous frame, or not touched at all.gammaREAL β gamma value found in the file.
Default: 0.45455
hasAlphaBOOLEAN β if set, the image contains an alpha channel.iccp_name,iccp_profileSTRING β embedded ICC color profiles in raw format.
Default: "unspecified" and "".
interlacedBOOL β if set, the PNG file is interlaced.
Default: 0
leftINTEGER β the horizontal offset of the frame from the screen.loopCountINTEGER β how many times the animation sequence should run, or0for forever. infinite loop era πmng_datastreamBOOL β if set, the file contains an MNG datastream.
Default: 0
offset_x,offset_yINT β a positive offset from the left edge of the screen tooffset_xand the positive offset from the left edge of the screen tooffset_y.
Default: 0
offset_dimensionpixel|micrometer β offset units.
Default: pixel
render_intentnone|saturation|perceptual|relative|absolute β see the PNG docs (http://www.libpng.org/pub/png/spec/1.1/PNG-Chunks.html, 4.2.9. sRGB Standard RGB color space).
Default: none
resolution_x,resolution_yINT β image resolution.
Default: 0
resolution_dimensionmeter|unknown β image resolution units.
Default: meter
scale_x,scale_yβ image scale factors.
Default: 1
scale_unitmeter|radian|unknown β image scale factor units.
Default: unknown
screenWidth,screenHeightINTEGERtextHASH β free-text comments found in the file.
Default: "{}"
topINTEGER β the vertical offset of the frame from the screen.transparency_table[INT] β when a paletted image contains transparent colors, returns an array of palette indexes (transparency_table) in the0-255range, where each number is an alpha value.
Default value: empty array
transparent_colorCOLOR β one transparent color value for 24-bit PNG images.
Default value: clInvalid (i.e. none)
transparent_color_indexINT β one transparent color value, as the palette index for 8- or less-bit PNG images.
Default value: -1 (i.e. none)
Not applicable for load.
ποΈ TIFF codec
Load input
MinIsWhiteBOOL β automatically invertPHOTOMETRIC_MINISWHITEimages.
Default: 1
FaxBOOL β if set, converts 1-bit grayscale with ratio2:1into 2-bit grayscale (algorithm also known as faxpect).
Default: 0
Load output
PhotometricSTRING β TIFFPHOTOMETRIC_XXXconstant. One of:
MinIsWhite
MinIsBlack
Palette
YCbCr
RGB
LogL
LogLUV
Separated
MASK
CIELAB
DEPTH
Unknown
BitsPerSampleINT β bits used to represent a single sample,1-64.SamplesPerPixel INTβ how many samples each pixel is carrying,1-4. Most images are out here living their simple life with1sample. Planar TIFFs might split the low and high bytes into2samples. RGB shows up with3samples, and YCbCr plus RGBA are serving4. π¨PlanarConfig contiguous|separateβ"separate"images split each individual sample or component (f.ex. R and G and B, bestie, like, individually) into their own planes."contiguous"mixes the sample bytes one after another. π«SampleFormat STRINGβ the pixel sample format, and it's one of these:
unsigned integer
signed integer
floating point
untyped data
complex signed int
complex floating point
Tiled BOOLβ if it's set, the TIFF is tiled. π§©Faxpect BOOLβ when the"Fax"option was set to"true", and the image genuinely got converted from 1 to 2 bits, this parameter gets set to signal exactly that. It's the little receipt, fr. πCompressionType STRINGβ the compression algorithm used for reading. One of:
NONE
CCITTRLE
CCITTFAX3
CCITTFAX4
LZW
OJPEG
JPEG
NEXT
CCITTRLEW
PACKBITS
THUNDERSCAN
IT8CTPAD
IT8LW
IT8MP
IT8BL
PIXARFILM
PIXARLOG
DEFLATE
ADOBE_DEFLATE
DCS
JBIG
SGILOG
SGILOG24
πΎ Save input
Compression STRINGβ same values as inCompressionType. The different name is there to avoid implicit but impossible compression selection, becausetibtiffcan decompress many types, but compress only a few. So bestie, read vs write are not the same menu, okay? π«Ά
π Load output and save input
- generic strings β these keys have no specific meanings for Prima, but they're both recognized for loading and saving:
Artist
Copyright
DateTime
DocumentName
HostComputer
ImageDescription
Make
Model
PageName
PageNumber
PageNumber2
PageNumber,PageNumber2 INTβ Default:1ResolutionUnit inch|centimeter|noneβ Default:noneSoftwareβ Default:PrimaπXPosition,YPosition INTβ Default:0XResolution,YResolution INTβ Default:1200
π GIF codec π
For GIF animation see Prima::Image::Animate. β¨
The following load output and save input keys are recognized:
comment STRINGβ the GIF comment text π¬delayTime INTβ delay in a hundredth of a second between frames. Default:1disposalMethod INTβ the animation frame disposal method:
DISPOSE_NOT_SPECIFIED = 0; # Leave frame, let new frame draw on top
DISPOSE_KEEP = 1; # Leave frame, let new frame draw on top
DISPOSE_CLEAR = 2; # Clear the frame's area, revealing bg
DISPOSE_RESTORE_PREVIOUS = 3; # Restore the previous (composited) frame
Default: 0
interlaced BOOLβ if it's set, the GIF image is interlaced. Default:0left,top INTβ frame offset in pixels. Default:0loopCount INTβ how many times the GIF animation loops.0means indefinite. Default:1πscreenBackGroundColor COLORβ GIF screen background color. Default:0screenColorResolution INTβ Default:256screenWidth,screenHeight INTβ Default:-1, i.e. use image width and heightscreenPalette [INT]β Default:0,0,0,255,255,255transparentColorIndex INTβ index of the GIF transparent color. Default:0userInput INTβ user input flag. Default:0
π¦ WebP codec π¦
π₯ Load output
background $ARGB_colorβ an integer constant encoded as 32-bit ARGB, hints the background color to be usedblendMethod blend|no_blend|unknownβ signals whether the new animation frame is to be blended over the existing animation, or it should replace that. πdelayTime $millisecondsβ delay time between framesdisposalMethod none|background|unknownβ signals whether the frame, before being replaced, is to be erased by the background color or not.hasAlpha BOOLEANβ if it's set, the image contains an alpha channelleft INTEGERβ the horizontal offset of the frame from the screenloopCount INTEGERβ how many times the animation sequence should run, or0for forever. βΎοΈscreenWidth INTEGERβ (that's the whole note, no extra lore)screenHeight INTEGERβ same deal, it's just listed πtop INTEGERβ the vertical offset of the frame from the screen
πΎ Save input
WebP requires all images to have the same dimensions. Also, saving the webp loading result might fail because loaded frames might only contain parts to be superimposed on each other while saving always requires full frames. To convert the loaded frames to something that can be saved later more-or-less identically, use the "Prima::Image::webp::animation_to_frames" converter:
use Prima qw(Image::webp);
my @i = Prima::Icon->load('source.webp', loadAll => 1, loadExtras => 1) or die $@;
@i = Prima::Image::webp::animation_to_frames(@i);
die $@ if @i != Prima::Icon->save('target.webp', images => \@i);
background $ARGB_colorβ an integer constant encoded as 32-bit ARGB, hints the background to be usedcompression lossless (default)|lossy|mixedβ pick your compression vibe ποΈdelay $millisecondsβ the gap between framesfilter_strength INTEGERβ the value is between0and100, where0means off.kmax INTEGERβ min distance between keyframes. The default is9for the lossless compression and3for the lossykmin INTEGERβ max distance between keyframes. The default is17for the lossless compression and5for the lossyloopCount 0β how many times the animation sequence should run, or0for forever.method INTEGERβ compression method vs size,0(fast) to6(slow)minimize_size BOOLEANβ minimize the output size (off by default)quality INTEGERβ quality factor (0:small..100:big)thread_level BOOLEANβ use multi-threading if available (off by default) π§΅
πΈ HEIF codec πΈ
π₯ Load output
chroma_bits_per_pixelβ no extra description here, it's just listed, iykykdepth_imagesβ number of depth images available for the framehas_alphaβ no extra notes on this one either πispe_height,ispe_widthβ original image size before transformations (crop, rotation, etc) are appliedis_primaryβ set if this is the primary image πluma_bits_per_pixelβ again, just the key, no descriptionpremultiplied_alphaβ is set if the values of the alpha channel are premultipliedthumbnailsβ an array of hashes with keystype,content_type, andcontent.auxβ listed, no notesmetadataβ listed, no notesthumbnail_of INDEXβ set if this frame is the thumbnail of the INDEXth top-level frame
πΎ Save input
qualityβ integer,0-100compressionβHEIC,AV1,AVCis_primaryβ the first frame (#0) gets to be the primary by default, but this can be changed explicitly.premultiplied_alphaβTruesetif the values of the alpha channel are premultipliedmetadataβ an array of hashes with keystype,content_type, andcontent.thumbnail_of INDEXβ sets this image as the thumbnail of the INDEXth top-level frame
π AUTHOR π
Dmitry Karasik, <dmitry@karasik.eu.org>.
π SEE ALSO π
Prima, Prima::Image, Prima::codecs, Prima::Image::Loader, Prima::Image::Exif, Prima::Image::base64.
And that's the whole page, bestie! π«Ά This lil' doc is living under perl v5.42.0 and was stamped 2024-08-20 β shoutout to the pod::Pr...ge-load(3) page for serving all this info. Go forth and load some images, you absolute icon π
β¨π
π¦ where this page comes from
- opensuse-leap 16.0: perl-Prima 1.74000-bp160.1.13 Β· AGPL-3.0-only AND BSD-2-Clause
- opensuse-leap 16.0: perl-Prima 1.74000-bp160.1.13 Β· AGPL-3.0-only AND BSD-2-Clause
- opensuse-leap 16.0: perl-Prima 1.74000-bp160.1.13 Β· AGPL-3.0-only AND BSD-2-Clause
- opensuse-leap 16.0: perl-Prima 1.74000-bp160.1.13 Β· AGPL-3.0-only AND BSD-2-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms