[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
CVS Update: gleipnir
- To: cvs@lists.cleannorth.org
- Subject: CVS Update: gleipnir
- From: Dan Brosemer <odin@cleannorth.org>
- Date: Sun, 17 Aug 2008 15:52:49 -0401 (EDT)
- List-help: <mailto:cvs-request@lists.cleannorth.org?subject=help>
- List-post: <mailto:cvs@lists.cleannorth.org>
- List-subscribe: <mailto:cvs-request@lists.cleannorth.org?subject=subscribe>
- List-unsubscribe: <mailto:cvs-request@lists.cleannorth.org?subject=unsubscribe>
- Resent-date: Sun, 17 Aug 2008 15:52:54 -0401 (EDT)
- Resent-from: cvs@lists.cleannorth.org
- Resent-message-id: <lsKelD.A.5uC.sGIqIB@skroob.cleannorth.org>
- Resent-sender: cvs-request@lists.cleannorth.org
Log Message:
-----------
Offload image processing in to Gleipnir::Image to prepare for rotate.
Modified Files:
--------------
gleipnir/public_html/gallery:
upload.pl
Added Files:
-----------
gleipnir/perllib/Gleipnir:
Image.pm
Revision Data
-------------
--- /dev/null
+++ perllib/Gleipnir/Image.pm
@@ -0,0 +1,100 @@
+###############################################################################
+# Image.pm - Image manipulation
+# $Id: Image.pm,v 1.1 2008/08/17 19:53:10 odin Exp $
+#
+# Copyright (C) 2000-2008 Dan Brosemer <odin@cleannorth.org>
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. The name of the author may not be used to endorse or promote products
+# derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+# THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+###############################################################################
+package Gleipnir::Image;
+
+use strict;
+
+use GD;
+use POSIX qw(ceil floor);
+
+sub Thumb
+ {
+ my %options = @_;
+ my $gleipnir = $options{-gleipnir};
+ my $image = $options{-image};
+ my $size = $options{-size};
+
+ my $width = $image->width();
+ my $height = $image->height();
+ my $wRatio = $size / $width;
+ my $hRatio = $size / $height;
+ my $thumbwidth = undef;
+ my $thumbheight = undef;
+
+ # Calculate a proportional width and height no larger than the max size.
+ if ( ($wRatio * $height) < $size )
+ {
+ # Image is horizontal
+ $thumbheight = ceil($wRatio * $height);
+ $thumbwidth = $size;
+ }
+ else
+ {
+ # Image is vertical
+ $thumbwidth = ceil($hRatio * $width);
+ $thumbheight = $size;
+ };
+
+ my $thumb = new GD::Image($thumbwidth, $thumbheight);
+ $thumb->copyResampled( $image, 0, 0, 0, 0, $thumbwidth, $thumbheight, $image->width(), $image->height() );
+
+ return $thumb;
+ };
+
+sub Watermark
+ {
+ my %options = @_;
+ my $gleipnir = $options{-gleipnir};
+ my $image = $options{-image};
+ my $iw = $options{-wmimage};
+ my $percent = $options{-alpha};
+
+ $iw->alphaBlending(0);
+ $percent /= 100.00;
+ for (my $h = 0; $h < $iw->height; ++$h)
+ {
+ for (my $x = 0; $x < $iw->width; ++$x)
+ {
+ my ($px, $alpha) = ();
+ $px = $iw->getPixel($x, $h);
+ $alpha = ($px >> 24) & 0xff;
+ next if ($alpha == 127);
+ $alpha += int((127 - $alpha) * $percent);
+ $alpha = 127 if ($alpha > 127);
+ $px = ($px & 0x00ffffff) | ($alpha << 24);
+ $iw->setPixel($x, $h, $px);
+ };
+ };
+ $iw->alphaBlending(1);
+ my $wmheight = $image->width/8/$iw->width*$iw->height;
+ $image->copyResampled($iw, $image->width-($image->width/8)-$gleipnir->cfetch(images=>'wmpad'), $image->height-$wmheight-$gleipnir->cfetch(images=>'wmpad'), 0, 0, $image->width/8, $wmheight, $iw->width, $iw->height);
+
+ return $image;
+ };
+
+1;
Index: upload.pl
===================================================================
RCS file: /cvs/gleipnir/public_html/gallery/upload.pl,v
retrieving revision 1.13
retrieving revision 1.14
diff -Lpublic_html/gallery/upload.pl -Lpublic_html/gallery/upload.pl -u -r1.13 -r1.14
--- public_html/gallery/upload.pl
+++ public_html/gallery/upload.pl
@@ -5,6 +5,7 @@
use GD;
use POSIX qw(ceil floor);
use Digest::SHA1 qw(sha1 sha1_hex sha1_base64);
+use Gleipnir::Image;
my $gleipnir = new Gleipnir;
do { print $gleipnir->output; exit } if ($gleipnir->done);
@@ -138,37 +139,7 @@
# Find the appropriate dimensions for the thumbnail
# Calculate aspect ratio
my $thumbmaxsize = $gleipnir->cfetch('images' => 'thumbsize');
- my $width = $image->width();
- my $height = $image->height();
- my $wRatio = $thumbmaxsize / $width;
- my $hRatio = $thumbmaxsize / $height;
- my $thumbwidth = undef;
- my $thumbheight = undef;
-
- # Calculate a proportional width and height no larger than the max size.
- if ( ($wRatio * $height) < $thumbmaxsize )
- {
- # Image is horizontal
- $thumbheight = ceil($wRatio * $height);
- $thumbwidth = $thumbmaxsize;
- }
- else
- {
- # Image is vertical
- $thumbwidth = ceil($hRatio * $width);
- $thumbheight = $thumbmaxsize;
- }
-
- # Create a thumbnail of an appropriate size
- my $thumb = new GD::Image($thumbwidth, $thumbheight);
- if ( !defined( $thumb ) )
- {
- $fail = 1;
- $message .= "Could not create thumbnail for image $filename <br>";
- $template->param(message => $message, failed => $fail );
- return $gleipnir->body($template->output);
- }
- $thumb->copyResampled( $image, 0, 0, 0, 0, $thumbwidth, $thumbheight, $image->width(), $image->height() );
+ 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
@@ -180,27 +151,9 @@
# Watermark
if ($gleipnir->cfetch(images => 'watermark'))
{
- my $percent = $gleipnir->cfetch(images => 'wmalpha');
my $iw = GD::Image->new($gleipnir->cfetch(images => 'watermark'));
- $iw->alphaBlending(0);
- $percent /= 100.00;
- for (my $h = 0; $h < $iw->height; ++$h)
- {
- for (my $x = 0; $x < $iw->width; ++$x)
- {
- my ($px, $alpha) = ();
- $px = $iw->getPixel($x, $h);
- $alpha = ($px >> 24) & 0xff;
- if ($alpha == 127) { next; };
- $alpha += int((127 - $alpha) * $percent);
- $alpha = 127 if ($alpha > 127);
- $px = ($px & 0x00ffffff) | ($alpha << 24);
- $iw->setPixel($x, $h, $px);
- };
- };
- $iw->alphaBlending(1);
- my $wmheight = $image->width/8/$iw->width*$iw->height;
- $image->copyResampled($iw, $image->width-($image->width/8)-$gleipnir->cfetch(images=>'wmpad'), $image->height-$wmheight-$gleipnir->cfetch(images=>'wmpad'), 0, 0, $image->width/8, $wmheight, $iw->width, $iw->height);
+ my $alpha = $gleipnir->cfetch(images => 'wmalpha');
+ $image = Gleipnir::Image::Watermark(-gleipnir => $gleipnir, -image => $image, -wmimage => $iw, -alpha => $alpha);
};
# Grab the image.
- Prev by Date: CVS Update: gleipnir
- Next by Date: CVS Update: gleipnir
- Previous by thread: CVS Update: gleipnir
- Next by thread: CVS Update: gleipnir
- Index(es):