Expensive resizing to multiple output files
Posted: 2017-06-08T07:57:00-07:00
Hello, I'm looking for less expensive way to resize one image to multiple output files.
Let's say I have one input JPEG image (i.e. 3500 x 2500 px, around 3MB). Is there a way to read this file once and resize it to multiple output formats, without reading the source file again? Currently I'm doing something like this:
The problem is with Read() which takes around 0.5 second (which is fast, but with 10 output formats reading alone takes 5 seconds).
If I put Read() outside loop then I do operations on the same picture. It's fast, but each scaling is using already scaled image. It causes problems when 1 format is very small and the next one is larger. I believe there has to be a way to always reach for source image without using the expensive Read() every time.
Thanks in advance for any hints or suggestions.
Yosh
Let's say I have one input JPEG image (i.e. 3500 x 2500 px, around 3MB). Is there a way to read this file once and resize it to multiple output formats, without reading the source file again? Currently I'm doing something like this:
Code: Select all
my $img = Image::Magick->new;
foreach my $outputfile(@outfiles) {
$img->Read($inputfile);
$img->Scale(geometry => "${scale}x${scale}");
$img->Write($outputfile);
@$img = ();
}
undef $img;
If I put Read() outside loop then I do operations on the same picture. It's fast, but each scaling is using already scaled image. It causes problems when 1 format is very small and the next one is larger. I believe there has to be a way to always reach for source image without using the expensive Read() every time.
Thanks in advance for any hints or suggestions.
Yosh