Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: Pure Perl - Crop and Resize Jpeg Files

by Your Mother (Archbishop)
on May 16, 2021 at 18:32 UTC ( #11132673=note: print w/replies, xml ) Need Help??


in reply to Re^2: Pure Perl - Crop and Resize Jpeg Files
in thread Pure Perl - Crop and Resize Jpeg Files

This version should do better (update: made more idiomatic/terse, it should really do aspect preservation to make a better image instead of translating an unknown aspect to a square)–

use strictures; use GD; use Path::Tiny; GD::Image->trueColor(1); my $original_image = GD::Image->new( shift || die "Give an image!\n" ) +; my $new_image = GD::Image->new(100, 100); $new_image->copyResampled( $original_image, 0, 0, 0, 0, $new_image->getBounds, $original_image->getBounds ); path("new.jpg")->spew_raw($new_image->jpeg);

The changes that make it “right” are GD::Image->trueColor(1) and $newimage->copyResampled instead of copyResized.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2022-01-28 21:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (73 votes). Check out past polls.

    Notices?