Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Imager: Gateway Timeout (updated (GD))

by vr (Curate)
on Dec 24, 2019 at 09:13 UTC ( [id://11110579]=note: print w/replies, xml ) Need Help??


in reply to Imager: Gateway Timeout

use strict; use warnings; use Time::HiRes 'time'; use Imager; my $t = time; my $i = Imager-> new( file => 'file.jpg' ); printf "image dimensions: %d x %d\n", $i-> getwidth, $i-> getheight; printf "reading: %.2f s\n", time - $t; $t = time; $i-> copy -> scale( xpixels => 750, qtype => 'normal' ) -> write( file => 'file+.jpg' ); printf "high quality resize & save: %.2f s\n", time - $t; $t = time; $i-> copy -> scale( xpixels => 750, qtype => 'mixing' ) -> write( file => 'file+.jpg' ); printf "medium quality resize & save: %.2f s\n", time - $t; $t = time; $i-> copy -> scale( xpixels => 750 * 4, qtype => 'mixing' ) -> scale( xpixels => 750, qtype => 'normal' ) -> write( file => 'file+.jpg' ); printf "medium+ quality resize & save: %.2f s\n", time - $t; $t = time; $i-> copy -> scale( xpixels => 750, qtype => 'preview' ) -> write( file => 'file+.jpg' ); printf "low quality resize & save:\t\t %.2f s\n", time - $t; $t = time; $i-> copy -> rotate( right => -90 ) -> write( file => 'file+.jpg' ); printf "fast rotate & save: %.2f s\n", time - $t; $t = time; $i-> copy -> rotate( degrees => -90 ) -> write( file => 'file+.jpg' ); printf "slow rotate & save: %.2f s\n", time - $t; __END__ image dimensions: 6083 x 4636 reading: 1.23 s high quality resize & save: 6.52 s medium quality resize & save: 1.17 s medium+ quality resize & save: 3.84 s low quality resize & save: 0.58 s fast rotate & save: 3.41 s slow rotate & save: 19.33 s

Some options were introduced for a reason... + Use medium size image as source for thumb (not shown above).

Updated: GD is so much faster, what do you mean "messed with colors"? Should work fine for geometric transformations.

use strict; use warnings; use Time::HiRes 'time'; use GD; my $t = time; my $i = GD::Image-> newFromJpeg( 'file.jpg', 1 ); printf "image dimensions: %d x %d\n", $i-> getBounds; printf "reading: %.2f s\n", time - $t; for ( 1 .. 20, 22, 23 ) { $t = time; $i-> interpolationMethod( $_ ); $i-> copyScaleInterpolated( 750, 572 ) -> _file( 'file+.jpg' ); printf "resize method \"$_\" & save: %.2f s\n", time - $t; } $t = time; $i-> copyRotateInterpolated( 90, 0 )-> _file( 'file+.jpg' ); printf "rotate & save: %.2f s\n", time - $t; __END__ image dimensions: 6083 x 4636 reading: 1.47 s resize method "1" & save: 0.59 s resize method "2" & save: 0.62 s resize method "3" & save: 0.07 s resize method "4" & save: 0.25 s resize method "5" & save: 0.24 s resize method "6" & save: 0.55 s resize method "7" & save: 0.53 s resize method "8" & save: 0.55 s resize method "9" & save: 0.55 s resize method "10" & save: 0.55 s resize method "11" & save: 0.53 s resize method "12" & save: 0.55 s resize method "13" & save: 0.55 s resize method "14" & save: 0.55 s resize method "15" & save: 0.53 s resize method "16" & save: 0.04 s resize method "17" & save: 0.54 s resize method "18" & save: 0.58 s resize method "19" & save: 0.62 s resize method "20" & save: 0.59 s resize method "22" & save: 0.09 s resize method "23" & save: 0.12 s rotate & save: 3.03 s

Interpolation constants here. 21st died on me.

Replies are listed 'Best First'.
Re^2: Imager: Gateway Timeout
by bliako (Monsignor) on Dec 24, 2019 at 10:30 UTC

    I get it! re: fast rotate vs slow rotate. It's the 90 (right angle, N*PI/2) degrees. so the fast one is just transposing the image pixels where the slow one does all sorts of averaging and interpolations. (Ref: rotations primer from leptonica library ). Imager could either warn user for using the slow rotate for right angles or just ignore user's wishes and do it the fast way. thanks, very enlightening.

Re^2: Imager: Gateway Timeout (updated (GD))
by cristofayre (Sexton) on Dec 24, 2019 at 12:45 UTC

    Gosh. Thanks for this imput. The first one makes a lot of ssense now; Once an image is created with the first $i -> copy, then future commands are simply instructions to the right of arrow, (I know it's not an arrow and has a special name!)as in "You've done this, now do this, and this ..."

    Somewhere on the web, I read that GD mutes the colours, and are thus not as vibrant. It might have been in reference to paletted GIF images, I'm not sure

    If those timings are correct,6secs, then it IS incredbly slow. It's gonna take 6 mins to process 59 images! If it takes the same sort of time on Linux server, my host (shared) may not be happy with me monopolising the CPU for that length of time! (OK, so this is a one off with this qty, and 'updates' will be in the 10 - 20 images range... but still seems slow

    I also heed the logic of creating the thumb from the medium size rather than starting from scratch on the full size image again. Makes more sense

    In that respect, GD seems to make more sense in terms of speed, so will give that a try. The 'quality' of medium and thumb are not too important (image preview and shop cart respectively) but people will be using the upright to print from. (I used API2::PDF to place the images in a "grid" so they can simply send the PDF to a commercial printer)

Re^2: Imager: Gateway Timeout (updated (GD))
by cristofayre (Sexton) on Dec 24, 2019 at 13:23 UTC

    Alas, seems Mssr Boutell's site is no more. Did find a zip for it on "PHP.net" ... which contains a series of folders, and no idea what goes where! (I have "C:/php") It also seems that you need to run dmake or sudo (?) to install (and call which file?)... and then you need to load a perl interface to it ... and source and install files to process jpeg files

    So looks like I'm back to Imager!

      Make life easy on yourself, if using Windows just download Strawberry perl, it has all sorts of useful, commonly used things installed be default.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11110579]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2024-04-26 09:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found