Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Image Uploader that Sizes the Photo Like An Avatar

by Anonymous Monk
on Jul 03, 2022 at 12:27 UTC ( #11145250=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello wise ones!

I'm looking to have users of my Web CGI script upload images using a form in their browser, and then prompt the users to crop whatever they upload to be square and no more than 600pixels in any dimension. I have no idea of any tools or modules I can use to do so.

Any advice? Thanks in advance!

  • Comment on Image Uploader that Sizes the Photo Like An Avatar

Replies are listed 'Best First'.
Re: Image Uploader that Sizes the Photo Like An Avatar
by hippo (Bishop) on Jul 03, 2022 at 13:50 UTC
Re: Image Uploader that Sizes the Photo Like An Avatar
by davies (Prior) on Jul 03, 2022 at 16:08 UTC
Re: Image Uploader that Sizes the Photo Like An Avatar
by kcott (Archbishop) on Jul 03, 2022 at 22:00 UTC

    Take a look at Image::Magick. Its description starts with (my emphasis):

    "This Perl extension allows the reading, manipulation and writing of a large number of image file formats using the ImageMagick library. It was originally developed to be used by CGI scripts for Web pages."

    A link to extensive documentation follows.

    I believe that module only handles raster formats; but happy to be proven wrong (I did have a quick look for a list of available formats: couldn't find one). I routinely use Image::LibRSVG to convert SVG (a vector format) to raster formats; I've no idea if that would be useful for you.

    — Ken

      Yes, Image::Magick will do this easily. I recommend actually, storing the full size image and hiding the resized image behind a webserver call (that might look like the all to an image or a RESTful GET call in an <img src...> tag. Note, image scale attacks exist, but I only mention them because they are an interesting adversary parlay against the bort.
Re: Image Uploader that Sizes the Photo Like An Avatar
by LanX (Sage) on Jul 03, 2022 at 12:33 UTC
    The crop part sounds rather like a JavaScript job ...

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

      Yes, in fact, this entire task sounds like a JavaScript job. From JavaScript, someone can put a local image from a hard drive to appear on the web page. Then the user can crop it, resize it using JavaScript. See Croppic.js. Then inside a canvas object, the JavaScript can get the new resized image pixel by pixel and convert it into any kind of format and upload it to the other side where your Perl script handles it. The JavaScript side of it is done by the Croppic library, so most of the work is already done for you.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11145250]
Front-paged by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2022-08-13 22:08 GMT
Find Nodes?
    Voting Booth?

    No recent polls found