The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Prima::Image::Loader - progressive loading and saving for multiframe images

DESCRIPTION

The toolkit provides functionality for session-based loadign and saving of multiframe images to that is is not needed to store all images in memory at once. Instead, the Prima::Image::Loader and Prima::Image::Saver classes provide the API for operating on a single frame at a time.

Prima::Image::Loader

        use Prima::Image::Loader;
        my $l = Prima::Image::Loader->new($ARGV[0]);
        printf "$ARGV[0]: %d frames\n", $l->frames;
        while ( !$l->eof ) {
                my ($i,$err) = $l->next;
                die $err unless $i;
                printf "$n: %d x %d\n", $i->size;
        }
new FILENAME|FILEHANDLE, %OPTIONS

Opens a filename or a file handle, tries to deduce if the toolkit can recognize the image, and creates an image loading handler. The %OPTIONS are same as recognized by "load" in Prima::Image except map, loadAll, and profiles. The other options apply to each frame that will be coonsequently loaded, but these options could be overridden by supplying parameters to the next call.

Returns either a new loader object, or undef and the error string.

Note that it is possible to supply the onHeaderReady and onDataReady callbacks in the options, however, note that the first arguments in these callbacks will the newly created image.

current INDEX

Manages the index of the frame that will be loaded next. When set, requests repositioning of the frame pointer so that the next call to next would load the INDEXth image.

eof

Return the boolean flag is the end of the file is reached.

extras

Returns the hash of extra file data filled by the codec

frames

Returns number of frames in the file

next %OPTIONS

Loads the next image frame.

Returns either a newly loaded image, or undef and the error string.

reload

In case an animation file is defect, and cannot be loaded in full, the toolkit will not allow to continue the loading session and will close it automatically. If it is desired to work around this limitation, a new session must be opened. The reload method does this by reopening the loading session with all the parameters supplied to new. The programmer thus has a chance to record how many successful frames were loaded, and only navigate these after the reload.

rescue BOOLEAN

If set, reopens the input stream or file on ever new frame. This may help recover broken frames.

source

Return the filename or the file handle passed to the new call.

Prima::Image::Saver

        my $fn = '1.webp';
        open F, ">", $fn or die $!;
        my ($s,$err) = Prima::Image::Saver->new(\*F, frames => scalar(@images));
        die $err unless $s;
        for my $image (@images) {
                my ($ok,$err) = $s->save($image);
                next if $ok;
                unlink $fn;
                die $err;
        }
new FILENAME|FILEHANDLE, %OPTIONS

Opens a filename or a file handle and an image saving handler. The %OPTIONS are same as recognized by "save" in Prima::Image except images. The other options apply to each frame that will be coonsequently saved, but these options could be overridden by supplying parameters to the save call.

Returns either a new saver object, or undef and the error string.

save %OPTIONS

Saves the next image frame.

Returns a success boolean flag and an eventual error string

AUTHOR

Dmitry Karasik, <dmitry@karasik.eu.org>.

SEE ALSO

Prima::Dialog::Animate.