Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Pure Perl - Crop and Resize Jpeg Files

by cormanaz (Deacon)
on Mar 16, 2006 at 01:09 UTC ( #537014=note: print w/replies, xml ) Need Help??

in reply to Pure Perl - Crop and Resize Jpeg Files

You should use GD for this. What you're talking about is simple using that library:
use GD; $image = GD::Image->new("myimage.jpg"); ($width,$height) = $image->getBounds() $newimage = new GD::Image(100,100); $newimage = copyResized($image,0,0, 0,0,100,100,$width,$height); open(IMG, "new.jpg") or die "Can't open output: $!"; binmode IMG; print IMG $newimage->jpeg; close IMG;
Good luck...


Replies are listed 'Best First'.
Re^2: Pure Perl - Crop and Resize Jpeg Files
by Bod (Curate) on May 16, 2021 at 17:42 UTC
    What you're talking about is simple using that library:

    With a bit of fiddling to correct the syntax errors, this code produces a distorted image - not a cropped image.

      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?

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2022-05-23 02:32 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (81 votes). Check out past polls.