Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can use the <code>Clone</code> method to copy an image. Also, writing an image and reading it immediately afterwards is redundant. Try something like the following:</p> <pre><code>my @sizes = ("1280","960","640","480","320","160"); my $src_image = Image::Magick-&gt;new; $x = $src_image-&gt;Read("/path/to/fullsize/image"); ######################### # Run the requested crop ######################### $x = $src_image-&gt;Crop(width=&gt;$input{w},height=&gt;$input{h},x=&gt;$input{x},y=&gt;$input{y}); foreach $size (@sizes) { my $image = $src_image-&gt;Clone; $resized = "/path/to/size/folders/$size\/$input{image_ID}\.png"; ############################################### # Size the image down to +2 pixels all around # to handle border opacity when pixel rounding ############################################### $temp_width = $size + 2; $temp_height = ($temp_width * $input{h}) / $input{w}; ########################### # Resize the cropped image ########################### $x = $image-&gt;Resize(width=&gt;$temp_width, height=&gt;$temp_height); ######################################## # Calculate final dimensions and coords ######################################## $final_height = ($size * $temp_height) / $temp_width; $final_x = 1; $final_y = 1; ####################################### # Final crop the image for clean edges ####################################### $x = $image-&gt;Crop(width=&gt;$size,height=&gt;$final_height,x=&gt;$final_x,y=&gt;$final_y); ######################################## # Write the final cropped image for use ######################################## $x = $image-&gt;Write("$resized"); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload