Learning is fun! You do fall off your surfboard a lot, though. I'm working on an image upload and resize CGI, and here's where I'm (look for the line with the obscene number of #s for where I'm having trouble):
#!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 Up +load 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/New +sThumbs'; 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 c +reate 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, $tar +getMaxY, $width, $height); $resizedImage->interlaced('true'); $newThumb->copyResized($buildable, 0, 0, 0, 0, $thumbMaxX, $thumbMax +Y, $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 { }
I'm trying to get this ironed out to work with the Jpegs first, then I'm hoping it'll be pretty straightforward to get other formats working as well. The current problem seems to be at line 87. GD::Image -> trueColor(1) sends me to the error message. I've tried doing a bit of monkeying around with it, but to no avail so far. I'm a novice yet, so be gentle :-). Cheers, K.

In reply to GD::Image trueColor() hangup... by kalchas

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.