try
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
use File::Copy;
use CGI::Carp 'fatalsToBrowser';
use Image::Resize;
my $q = CGI->new;
my $photo = $q->param("pic");
my ($ext) = $photo =~ /([^.]+)$/;
my $msg = '';
my $newfile = "100x100.$ext"; # change as req
if ($ext =~ /jpe?g|png/i){
my $copydir = '/var/www/html/img/';#/full/path/to/web/img/';
my $image = Image::Resize->new($photo);
my $gd = $image->resize(100, 100);
open OUTFILE,'>',$copydir.$newfile
or die "Could not open $copydir$newfile : $!";
binmode OUTFILE;
if ($ext =~ /jpe?g/){
print OUTFILE $gd->jpeg();
} else {
print OUTFILE $gd->png;
}
close OUTFILE;
$msg = "OK: File $photo uploaded";
} else {
$msg = "ERROR: Image must be jpeg/jpg or png not '$ext'";
}
print $q->header;
print << "HTM";
<h2>File upload</h2>
<form method="post" action="" enctype="multipart/form-data">
Filename: <input type="file" accept="image/*" name="pic"/><br/><br/>
<input type="submit"/>
</form>
<pre>$msg</pre>
<img src="/img/$newfile"/>
HTM
Note : This works because $q->param('pic') can return both a filename and a filehandle. Although it's not explicit in the documentation Image::Resize->new() will accept a filehandle as it uses GD::Image->new($image) to create the object.
poj