ndnalibi has asked for the wisdom of the Perl Monks concerning the following question:

Is there a way to load an image into memory and access that image from memory?

I have a script that creates thousands of images based upon the same base images and I am trying to optimize the program. In other programs I've been able to store reference to objects in an array that sped up the program, but in that case the final output was a large PDF with multiple pages. In this case the images are opened, combined and then saved over and over.

I've tried using open and read but I cannot reference this in my script due to the encoded data (which includes " and ` characters)

Any help would be appreciated.

Bill

Replies are listed 'Best First'.
Re: Loading images in memory
by boftx (Deacon) on Nov 26, 2013 at 18:38 UTC

    I would think it would depend on what module and underlying library you are using. IIRC ImageMagik allows manipulating images stored in memory over and over.

    It helps to remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.
Re: Loading images in memory
by Anonymous Monk on Nov 26, 2013 at 18:36 UTC

    I've tried using open and read but I cannot reference this in my script due to the encoded data (which includes " and ` characters)

    what does that mean?

    Any help would be appreciated.

    question sounds too generic for an answer to be possible, but I'll try

    Does this help?

    use Path::Tiny qw/ path /; my $rawfile = path( $file )->slurp_raw open my($filehandle), '<:raw', \$rawfile; ## in memory ... close $filehandle;
Re: Loading images in memory
by taint (Chaplain) on Nov 26, 2013 at 20:25 UTC

    Would Image::Magick offer any routines to help you with this?

    Has quite a few plugins, as well.

    --Chris

    #!/usr/bin/perl -Tw
    use Perl::Always or die;
    my $perl_version = (5.12.5);
    print $perl_version;
      Post a sensible answer, or don't post at all. It's ok not to know the answer. Stop guessing and suggesting untested rubbish. Examples, runable code ++.
        Given the vagueness of the question. It's difficult imagine that you could possibly discern the quality of my reply.

        In fact, I wrote a simple script some 10yrs. ago using Image::Magick to turn an image (gif,jpg,png) into a pure text version of the original, color, and all. It does the entire operation within memory.

        I'd have offered a coded solution/correction. But the OP couldn't be bothered to post theirs.

        --Chris

        #!/usr/bin/perl -Tw
        use Perl::Always or die;
        my $perl_version = (5.12.5);
        print $perl_version;