Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

How can I predict which image will big smaller ?

by palkia (Scribe)
on Aug 03, 2012 at 14:34 UTC ( #985250=perlquestion: print w/replies, xml ) Need Help??
palkia has asked for the wisdom of the Perl Monks concerning the following question:

Hi everyone.
I'm trying to find a way to predict which image (Imager)
will take the smaller size once saved to a file (before saving).
Since I'm planning this process to run many times,
I don't want to slow down my program by actually saving the images to files and than comparing sizes, and removing the bigger one.

Your thoughts ?
  • Comment on How can I predict which image will big smaller ?

Replies are listed 'Best First'.
Re: How can I predict which image will big smaller ?
by BrowserUk (Pope) on Aug 03, 2012 at 14:55 UTC

    Why not have it write all the filetypes to a ramfile first:

    my %sizes; for my $type ( Imager->write_types ) { open my $ramFH, '>:raw', \$buffer; $im->write( fh => $ramFH, type => $type ); $sizes{ length $buffer } = $type; } ## Pick type of smallest my $filetype = $sizes{ (sort{ $a <=> $b } keys %sizes)[0] }; ## write to real file ...

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

Re: How can I predict which image will big smaller ?
by ww (Archbishop) on Aug 03, 2012 at 15:06 UTC
    Did you read the documentation?
    ... especially
    # try to save in one of these formats
    (assumption: you mean smaller file size).

    Or, "# Create smaller version
    # documented in Imager::Transformations
    if "smaller size" refers to dimensions in pixels.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://985250]
Approved by BrowserUk
and a kettle whistles...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2017-06-23 02:34 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (533 votes). Check out past polls.