Hi Monks!
I am working on this code and before I upload the photos to the server I need to resize these pictures, I cant get to work. If anyone would look into this code and help me would be very nice!
#!/usr/bin/perl -w
use strict;
use CGI::Carp qw( fatalsToBrowser );
use CGI ':standard';
use Image::Size;
use Image::Magick;
my (@inx,$ac,$ar,@filename,@array_reference,@working_filename,$array_b
+egin,$array_end,$in,$save_file);
my $image = Image::Magick->new;
my $upload_dir = "../../pics";
$CGI::POST_MAX = 2048;
binmode(STDIN);
@inx = <STDIN>;
#my ($ac,$ar);
$ac = 0;
$ar = 0;
foreach (@inx) {
delete @inx[$ac] if $_ =~ /^Content-Type: application\/octet-stream
+/;
$ac++;
}
$ac = 0;
# Define individual uploaded files within the array
foreach (@inx) {
if ($_ =~ /^Content-Type/) {
$filename[$ar] = $inx[$ac-1];
$array_reference[$ar] = $ac;
@working_filename = split /filename=/, $filename[$ar];
@working_filename = split /"/, $working_filename[1]; # "
@working_filename = split /\\/, $working_filename[1];
$filename[$ar] = pop @working_filename;
$ar++;
}
$ac++;
}
$ac = 0;
$ar = 0;
print "content-type: text/html\n\n";
# Pull files from the array and write to disk
foreach (@filename) {
$array_begin = $array_reference[$ac] + 2;
$array_begin = 0 if $array_begin < 0;
$array_end = $array_reference[$ac+1] - 3;
$array_end = ($#inx) if $array_end < 0;
for (my $ii = $array_begin; $ii <= $array_end; $ii++) {
$in .= $inx[$ii];
}
$in = substr($in,0,length($in) - 2);
$save_file = "$upload_dir/$_";
# get the image size
my( $width, $height ) = imgsize($save_file);
# resize image files here
$image->read('$save_file');
$image->Set( Gravity => 'Center' );
$image->Resize( geometry => '180x168' );
$image->Extent( geometry => '180x168' );
my $n_image = $image->Write( '$save_file' );
# get the new image size here and save the new file size to dir
my( $width2, $height2 ) = imgsize($n_image);
# I am printing here to make sure the photo has been resizedm but i
+t is not working
print "<br>2-$width2, $height2<br>";
open(FF,">$save_file") or die $!;
binmode(FF);
print FF $in;
close(FF);
$in = "";
$ac++;
print "Uploaded file $save_file<br />";
print "<IMG src=\"$save_file\" width=\"180\" height=\"168\">";
}
Thanks!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.