Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Upload with image resizing by Image::Magick

by TWValentine (Initiate)
on Jan 20, 2009 at 17:41 UTC ( [id://737628]=perlquestion: print w/replies, xml ) Need Help??

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

I've been fighting with my own upload script, but have failed to make it work. I need an uploader that resizes image files and generates thumbs on my server. The location of the uploaded file and thumb will be added to a MySQL database. I can do that with little effort, but this script is driving me crazy. This has probably been asked a million times, but I've failed to find anything like what I need on other sites (for free). I'd like to use Image::Magick for the resizing. Can someone point out a good uploader that does what I need? Either that or post a simple uploader here? Thanks for your help!
  • Comment on Upload with image resizing by Image::Magick

Replies are listed 'Best First'.
Re: Upload with image resizing by Image::Magick
by Corion (Patriarch) on Jan 20, 2009 at 17:57 UTC

    Basically, CGI.pm has everything you need for the "uploader" part. You don't show any code nor do you tell us where it failed for you, so we can't be of much help there. Adding the file (contents) to the database is then easily done using DBI.

    You can use Image::Magick or the external convert utility (which often is easier available) or possibly Imager for resizing your image. It isn't that hard to write such a program.

    This is not a script writing site. We will gladly help you with your problems, but we don't write complete programs unless they are particularly interesting.

Re: Upload with image resizing by Image::Magick
by jeffa (Bishop) on Jan 20, 2009 at 18:34 UTC

    File uploading is not exactly a safe thing to do. That doesn't mean one shouldn't do it -- this just means that one shouldn't expect to find a script that handles uploads for their needs in a secure manner. We often use the phrase "don't reinvent the wheel" around here a lot -- but this is one wheel that has too many specific security concerns to be only rolled once. As such, i recommend that you first study what is required to make file upload work. merlyn has an old Web Techniques article that may be of use to you. You won't be able to use the code, but you should be able to learn from it. Good luck! :)

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
Re: Upload with image resizing by Image::Magick
by derby (Abbot) on Jan 20, 2009 at 18:50 UTC

    I know it's heresy but given the fits Image::Magick has caused me in the past, I find it easier to just fork/exec ImageMagick's convert utility.

    -derby
Re: Upload with image resizing by Image::Magick
by MidLifeXis (Monsignor) on Jan 20, 2009 at 20:12 UTC
Re: Upload with image resizing by Image::Magick
by Lawliet (Curate) on Jan 20, 2009 at 21:20 UTC

    Hah, I had the exact same task a few days ago. I ended up using Graphics::Magick to resize and then DBI to insert the locations of both the thumbnail and original along with general information about the original picture. Unfortunately for you, however, this here program is not on the computer I am using.

    The reason I used Graphics::Magick instead of Image::Magick is because I got tired of trying to install the latter after two days. I think the commands are the same, though. It went something like:

    sub thumbnailize { my ($pic, $thumb) = @_; my $image = Graphics::Magick->new; my $err; $err = $image->Read($pic); warn $err if $err; $err = $image->Scale(geometry => '200x200'); warn $err if $err; $err = $image->Write($thumb); warn $err if $err; }

    Pretty simple after reading the documentation. :)

    And you didn't even know bears could type.

Re: Upload with image resizing by Image::Magick
by andye (Curate) on Jan 21, 2009 at 11:58 UTC
    The way I've done it in the past:

    - receive the file upload using CGI.pm or Apache::Whatever

    - save it (making sure the filename is untainted)

    - ask image magick if the file is an image of one of the types you're willing to accept (delete it if not)

    - run image magick's resizing thingy as a system call. let the web server return a page to the user, while leaving IM to get on with things (because it can take a while for big files).

    Also, be aware that image magick resizing can use a lot of memory for large files. so you might want to restrict the size of the file upload.

    hth!

    andye

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-25 09:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found