my $mainImg = $self->query->param('propImg'); my $id = $self->query->param('pId') || $self->param('DBH')->{mysql_insertid}; if ($mainImg) { warn " ( $id ) directory ... " . FINALDIR if DEBUG; my $utils = MLSUtils->new(); my $fsName = $utils->save_to_filesystem( $self->query, FINALDIR, 'propImg' ); my ( $base, $dir, $suffix ) = fileparse( $fsName, qr{\..*} ); my $newImgName = FINALDIR . "/LG${id}_0" . $suffix; warn "passing $newImgName to resizeImg " if DEBUG; $utils->resizeImg( $fsName, $newImgName, 1 ) or die "Resizing images failed! "; $sth = $self->param('DBH')->prepare( "UPDATE jbg_managed_props SET NumPhotos = 1 WHERE jbgPropertyID = ? " ); $sth->execute($id) if ( !$self->query->param('pId') ); } warn "back from images " if DEBUG; #### sub resizeImg { my ( $self, $imageName, $newImageName, $mkThumb ) = @_; die("Cannot resize null image value") unless ($imageName); warn "before regex: imageName --> $imageName " if DEBUG; warn "before regex: newImageName --> $newImageName " if DEBUG; my ( $base, $dir, $suffix ) = fileparse( $imageName, qr{\..*} ); my ( $base2, $dir2, $suffix2 ) = fileparse( $newImageName, qr{\..*} ); $base2 =~ s/LG/TH/; my $tmpName = IMAGEDIR . '/' . $imageName; my $fileName = $newImageName; my $large = Image::Magick->new() or die "NO IMAGE READ!!!: $!"; my $filesRead = $large->Read($imageName); my $thumb = $large->Clone(); my ( $height, $width ) = $large->Get( 'height', 'width' ); my $reduceWlg = LG_MAX_WIDTH / $width; my $reducePercent = $reduceWlg; my $newH = $height * $reducePercent; my $newW = $width * $reducePercent; warn "new IMG: $fileName " if DEBUG; my $attempts; FILEWRITE: { $attempts++; eval { open( NEWIMG, ">$fileName" ) or die "Can't open new imagefile: ($fileName) $! \n"; binmode(NEWIMG); warn "after OPEN and BINMODE" if DEBUG; ###3 don't forget! Image::Magick functions don't have return values $large->Resize( height => $newH, width => $newW ) ; # or die "Resizing error: $! \n"; warn "RESIZE worked! " if DEBUG; $large->Write( file => \*NEWIMG ); # or die "Write error: $!\n"; warn "WRITE worked! " if DEBUG; close(NEWIMG); }; warn "trying to write the new file ( $fileName ) failed: $@ " if ($@); redo FILEWRITE if ( $@ and $attempts < 3 ); } #undef $large; warn "New LG image written" if DEBUG; if ($mkThumb) { my $thumbName = "${dir2}/${base2}${suffix2}"; warn "thumb : $thumbName " if DEBUG; my $reduceWth = TH_MAX_WIDTH / $width; $reducePercent = $reduceWth; $newH = $height * $reducePercent; $newW = $width * $reducePercent; $thumb->Resize( height => $newH, width => $newW ); open( NEWIMG, ">$thumbName" ) or die "Can't open new imagefile: ($thumbName) $! \n"; $thumb->Write( file => \*NEWIMG ); close(NEWIMG); warn "New TH image written" if DEBUG; } warn "exiting sub resizeImg()" if DEBUG; return 1; } #### [Wed Jul 14 19:10:13 2004] admin.cgi: passing /home/httpd/jbgoodwin.com/html/image/LG6_6.jpg to resize img at /home/httpd/jbgoodwin.com/libs/AdminFunctions.pm line 394. [Wed Jul 14 19:10:13 2004] admin.cgi: before regex: imageName --> /home/httpd/jbgoodwin.com/html/image/Provance Model living 6.jpg at /home/httpd/jbgoodwin.com/libs/MLSUtils.pm line 84. [Wed Jul 14 19:10:13 2004] admin.cgi: before regex: newImageName --> /home/httpd/jbgoodwin.com/html/image/LG6_6.jpg at /home/httpd/jbgoodwin.com/libs/MLSUtils.pm line 85. [Wed Jul 14 19:10:13 2004] admin.cgi: new IMG: /home/httpd/jbgoodwin.com/html/image/LG6_6.jpg at /home/httpd/jbgoodwin.com/libs/MLSUtils.pm line 108. [Wed Jul 14 19:10:13 2004] admin.cgi: after OPEN and BINMODE at /home/httpd/jbgoodwin.com/libs/MLSUtils.pm line 119. [Wed Jul 14 19:10:13 2004] admin.cgi: RESIZE worked! at /home/httpd/jbgoodwin.com/libs/MLSUtils.pm line 123. [Wed Jul 14 19:10:13 2004] admin.cgi: WRITE worked! at /home/httpd/jbgoodwin.com/libs/MLSUtils.pm line 126. [Wed Jul 14 19:10:13 2004] admin.cgi: New LG image written at /home/httpd/jbgoodwin.com/libs/MLSUtils.pm line 136. [Wed Jul 14 19:10:13 2004] admin.cgi: exiting sub resizeImg() at /home/httpd/jbgoodwin.com/libs/MLSUtils.pm line 158. [Wed Jul 14 19:10:13 2004] [error] [client 24.173.210.82] Premature end of script headers: /home/httpd/jbgoodwin.com/html/admin/admin.cgi