[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CVS Update: gleipnir



Log Message:
-----------
Keep images in same format as they were uploaded

Modified Files:
--------------
    gleipnir/public_html/gallery:
        upload.pl

Revision Data
-------------
Index: upload.pl
===================================================================
RCS file: /cvs/gleipnir/public_html/gallery/upload.pl,v
retrieving revision 1.6
retrieving revision 1.7
diff -Lpublic_html/gallery/upload.pl -Lpublic_html/gallery/upload.pl -u -r1.6 -r1.7
--- public_html/gallery/upload.pl
+++ public_html/gallery/upload.pl
@@ -101,12 +101,13 @@
 	$filename =~ s/.*[\/\\](.*)/$1/;
 
 	$xtn = (split /\./, $filename)[-1];
+	my $fmt = ($xtn =~ m/jpe?g/i)?'jpg':'png';
 
 	# Copy our original image to somewhere safeish
 	open ( ORIGIMAGE, ">$originaldir/$id.$xtn" ) or $fail = 1;
 	if ( $fail > 0 )
 	{
-		$message = " Could not open Image File to write: $! at $originaldir/$id.png";
+		$message = " Could not open Image File to write: $! at $originaldir/$id.$fmt";
   	$template->param(message => $message, failed => $fail );
 		return $gleipnir->body($template->output);
 	}
@@ -127,22 +128,22 @@
 		return $gleipnir->body($template->output);
 	}
 
-	# Grab the image in png form.
-	my $image_png = $image->png();
+	# Grab the image.
+	my $image_out = ($fmt eq 'png')?$image->png():$image->jpeg();;
 
 	# Grab a SHA1 hash for later
-	my $hash = sha1_hex( $image_png );
+	my $hash = sha1_hex( $image_out );
 	
-	# Convert the image to a png and write it out to a file 
-	open( MYIMAGE, ">$storagedir/$id.png" ) or $fail = 1;
+	# Write it out to a file 
+	open( MYIMAGE, ">$storagedir/$id.$fmt" ) or $fail = 1;
 	if ( $fail > 0 )
 	{
-		$message = " Could not write Image file: $! at $storagedir/$id.png"; 
+		$message = " Could not write Image file: $! at $storagedir/$id.$fmt"; 
   	$template->param(message => $message, failed => $fail );
 		return $gleipnir->body($template->output);
  	}
 	binmode MYIMAGE;
-	print MYIMAGE $image_png;
+	print MYIMAGE $image_out;
 	close MYIMAGE;
 	
 	# Find the appropriate dimensions for the thumbnail
@@ -180,10 +181,11 @@
 	}
  	$thumb->copyResampled( $image, 0, 0, 0, 0, $thumbwidth, $thumbheight, $image->width(), $image->height() );
 
+	my $thumb_out = ($fmt eq 'png')?$thumb->png():$thumb->jpeg();;
 	# Write the thumbnail out to a file
-	open (MYTHUMBNAIL, ">$thumbdir/$id.png" );
+	open (MYTHUMBNAIL, ">$thumbdir/$id.$fmt" );
 	binmode MYTHUMBNAIL;
-	print MYTHUMBNAIL $thumb->png();
+	print MYTHUMBNAIL $thumb_out;
   close MYTHUMBNAIL;
 
 	my $aSQL =<<EOT;
@@ -193,7 +195,7 @@
 	my $acursor = $dbh->prepare($aSQL);
 
 	# Upload the picture info to our database
-	$acursor->execute( $id, $hash, $gleipnir->uid, $galleryid, "$id.png", "$id.$xtn", "$id.png", $caption, $title );
+	$acursor->execute( $id, $hash, $gleipnir->uid, $galleryid, "$id.$fmt", "$id.$xtn", "$id.$fmt", $caption, $title );
 	
   $template->param(message => $message, failed => $fail );
 	return $gleipnir->body($template->output);


Main Menu:

Site Tools:


Here, spammer, have some addresses.