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

CVS Update: gleipnir



Log Message:
-----------
Add rotation

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

Revision Data
-------------
Index: picture.pl
===================================================================
RCS file: /cvs/gleipnir/public_html/gallery/picture.pl,v
retrieving revision 1.8
retrieving revision 1.9
diff -Lpublic_html/gallery/picture.pl -Lpublic_html/gallery/picture.pl -u -r1.8 -r1.9
--- public_html/gallery/picture.pl
+++ public_html/gallery/picture.pl
@@ -32,6 +32,7 @@
 use strict;
 use Gleipnir;
 use MIME::Types;
+use GD;
 
 my $gleipnir = new Gleipnir ( -noredir => 1);
 my $cgi      = $gleipnir->cgi;
@@ -44,6 +45,14 @@
 	{
 		$gleipnir = DoDelete( -gleipnir => $gleipnir );
 	}
+elsif ($cgi->param('action') eq 'rotate90')
+	{
+		$gleipnir = Rotate( -gleipnir => $gleipnir, -angle => 90 );
+	}
+elsif ($cgi->param('action') eq 'rotate270')
+	{
+		$gleipnir = Rotate( -gleipnir => $gleipnir, -angle => 270 );
+	}
 else
 	{
 		$gleipnir = ShowPage( -gleipnir => $gleipnir );
@@ -136,4 +145,89 @@
 		$cursor->execute($pictureid);
 
 		return $gleipnir->url('/gallery/?gallery='.$gallery);
+	};
+
+sub Rotate
+	{
+		my %options  = @_;
+		my $gleipnir = $options{-gleipnir};
+		my $cgi      = $gleipnir->cgi;
+		my $dbh      = $gleipnir->dbh;
+		my $angle    = $options{-angle};
+
+		my $pictureid = $cgi->param('id')||($ENV{PATH_INFO} =~ m%/(\d+)\.(jpg|png|jpeg)$%i)[0];
+
+		my $SQL = <<EOT;
+select gp.gallery, g.gid, thumb_path, image_path, original_path, rotated from gallery_picture gp left join gallery g
+on gp.gallery = g.galleryid
+where pictureid = ?
+EOT
+
+		my $cursor = $dbh->prepare($SQL);
+		$cursor->execute($pictureid);
+		my ($gallery, $gid, $thumb, $curimage, $original, $rotated) = $cursor->fetchrow;
+		return $gleipnir->error('403') if defined($gid) and !$gleipnir->ingroup($gid);
+		$rotated ||= 0;
+		$rotated += $angle;
+		$rotated %= 360;
+
+		my $image = GD::Image->new($gleipnir->cfetch(dirs => 'originals').'/'.$original);
+		if ($rotated == 0)
+			{
+			}
+		elsif ($rotated == 90)
+			{
+				$image = $image->copyRotate90();
+			}
+		elsif ($rotated == 180)
+			{
+				$image = $image->copyRotate180();
+			}
+		elsif ($rotated == 270)
+			{
+				$image = $image->copyRotate270();
+			};
+
+		my $xtn = (split /\./, $original)[-1];
+		my $fmt = ($xtn =~ m/jpe?g/i)?'jpg':'png';
+
+		my $originaldir = $gleipnir->cfetch( dirs => 'originals' );
+		my $storagedir = $gleipnir->cfetch( dirs => 'imagedir' );
+		my $thumbdir = $gleipnir->cfetch( dirs => 'thumbdir' );
+
+		my $thumbmaxsize = $gleipnir->cfetch('images' => 'thumbsize');
+		my $thumb = Gleipnir::Image::Thumb(-gleipnir => $gleipnir, -image => $image, -size => $thumbmaxsize);
+
+		my $thumb_out = ($fmt eq 'png')?$thumb->png():$thumb->jpeg();;
+		# Write the thumbnail out to a file
+		open (MYTHUMBNAIL, ">$thumbdir/$pictureid.$fmt" );
+		binmode MYTHUMBNAIL;
+		print MYTHUMBNAIL $thumb_out;
+		close MYTHUMBNAIL;
+
+		# Watermark
+		if ($gleipnir->cfetch(images => 'watermark'))
+			{
+				my $iw = GD::Image->new($gleipnir->cfetch(images => 'watermark'));
+				my $alpha = $gleipnir->cfetch(images => 'wmalpha');
+				$image = Gleipnir::Image::Watermark(-gleipnir => $gleipnir, -image => $image, -wmimage => $iw, -alpha => $alpha);
+			};
+
+		# Grab the image.
+		my $image_out = ($fmt eq 'png')?$image->png():$image->jpeg();;
+		open( MYIMAGE, ">$storagedir/$pictureid.$fmt" );
+		binmode MYIMAGE;
+		print MYIMAGE $image_out;
+		close MYIMAGE;
+
+		$SQL = <<EOT;
+update gallery_picture
+set rotated = ?
+where pictureid = ?
+EOT
+
+		$cursor = $dbh->prepare($SQL);
+		$cursor->execute($rotated, $pictureid);
+
+		return $gleipnir->url('/gallery/picture.pl?id='.$pictureid);
 	};


Main Menu:

Site Tools:


Here, spammer, have some addresses.