Manipulating POST files
Posted: 2011-07-23T11:20:14-07:00
How can I manipulate images submitted through a form using POST?
Basically I want to make sure that images are no bigger than a certain size (width and height) and if they are bigger than scale them down.
My first attempt was to try to get the POST image to display simply as it is recieved. I tried;
I know that this code is way off, I need to access the file itself not the filename ($query->param('uploadedfile');) so I tried using my $filename = $query->upload('uploadedfile'); but as of yet I have had no success. Could someone tell me how this is accomplished. I was thinking that maybe I needed to access the temp file that CGI creates for the image, is that the way to go about it?
Or do I simply have to save the file to the server first and then open it?
Basically I want to make sure that images are no bigger than a certain size (width and height) and if they are bigger than scale them down.
My first attempt was to try to get the POST image to display simply as it is recieved. I tried;
Code: Select all
#!/usr/bin/perl
use strict;
use warnings;
use Image::Magick;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
my $query = CGI->new;
my $image = Image::Magick->new;
my $filename = $query->param('uploadedfile');
my $status = $image->Read( $filename );
die "Couldn't open image: $status" if $status;
binmode STDOUT;
print $query->header( -type => "image/png" );
$image->Display();
Or do I simply have to save the file to the server first and then open it?