#!C:\Perl\bin\perl.exe -wT ## use strict; use warnings; use CGI; use CGI::Carp qw/fatalsToBrowser/; use File::Basename; $CGI::POST_MAX = 1024*5000; $CGI::DISABLE_UPLOADS = 0; my $query = CGI->new; my $safeCharacters = 'a-zA-Z0-9_.-'; my $uploadDirectory = 'C:/Apache/htdocs/notoriousteaze.com/Images/Temp'; my $originalImage = $query->param("Image"); my ($filename, undef, $ext) = fileparse($originalImage, qr(\..*)); $filename .= $ext; $filename =~ tr/ /_/; $filename =~ s/[^$safeCharacters]//g; if ($filename =~ /^([$safeCharacters]+)$/) { $filename = $1; } else { error("That file name doesnt work for me. $filename"); } my $uploadFilename = $query->upload("Image"); open(UPLOADFILE, ">$uploadDirectory/$filename") or error('Could Not Upload File.'); while ( <$uploadFilename> ) { print UPLOADFILE; } close UPLOADFILE; my %resizeFileType = ( ".jpeg" => \&resizeJpeg, ".jpg" => \&resizeJpeg, ".gif" => \&resizeGif, ".png" => \&resizePng, ); if(defined ($resizeFileType{$ext})) { $resizeFileType{$ext}->($uploadDirectory, $filename); } else { error("Not seeing the filetype: $ext"); } sub error { my $error = shift(); print $query->header(), $query->start_html(-title=>'Error'), $error, $query->end_html; exit(0); } sub resizeJpeg($$) { use GD; my $newDirectory = 'C:/Apache/htdocs/notoriousteaze.com/Images/News'; my $thumbDirectory = 'C:/Apache/htdocs/notoriousteaze.com/Images/NewsThumbs'; my $source = "$uploadDirectory/$filename"; my $target = "$newDirectory/$filename"; my $thumbTarget = "$thumbDirectory/$filename"; my $targetMaxX = 250; my $targetMaxY = 250; my $thumbMaxX = 80; my $thumbMaxY = 80; ##$source = shift(); ##$target = shift(); ##$thumbTarget = shift(); GD::Image->trueColor(1) or error("$source, filename: $filename"); ##################This is where it seems to be conking out on me!!################################################################# $buildable = newFromJpeg GD::Image($source, 1) or error('Could not create Image.'); (my $width, my $height) = $buildable=> getbounds(); if ($width > $height) { $targetMaxY = $height / ($width / $targetMaxX); $thumbMaxY = $height / ($width / $thumbMaxX); } else { $targetMaxX = $width / ($height / $targetMaxY); $thumbMaxX = $width / ($height / $thumbMaxY); } my $resizedImage = newTrueColor GD::Image($targetMaxX, $targetMaxY); my $newThumb = newTrueColor GD::Image($thumbMaxX, $thumbMaxY); $resizedImage->copyResized($buildable, 0, 0, 0, 0, $targetMaxX, $targetMaxY, $width, $height); $resizedImage->interlaced('true'); $newThumb->copyResized($buildable, 0, 0, 0, 0, $thumbMaxX, $thumbMaxY, $width, $height); $newThumb->interlaced('true'); open(DATEI, ">$target") or error('Could not write to target file.'); while ( <$resizedImage> ) { print DATEI; } close DATEI; open(DATEI, ">$thumbTarget") or error('Could not write to thumb file.'); while ( <$resizedImage> ) { print DATEI; } close DATEI; } sub resizeGif { } sub resizePNG { }