Phoenix.pm: Job (Sort of :) Fwd: looking for Perlmongers who can spare 5 mins

Eden Li Eden.Li at asu.edu
Tue Oct 10 20:31:26 CDT 2000


Here's a start, it does JPEG images..  it uses the GD library which is
availible for most platforms.  Right now no gif support is included with
GD, but there are certain current versions of GD that do GIFs.. i'm not
sure Perl GD supports them :/... anyway it's attached, email me at
Eden.Li at asu.edu if you need help with it.

Eden

Doug and Julie Miles <djmilesfamily at earthlink.net> wrote:
> >I am looking for a script that is very similar to the PerlMagic Mogrify 
> >tools, except that I can't install the ImageMagick program on the server 
> >(NT server).  The script requirements are VERY simple:
> >
> >1. I want to pass a single image (jpeg or gif) at the command line to the 
> >script (ie : img src="/cgi-bin/resize.cgi?betty.jpg">).  The original 
> >image is either GIF or JPEG (I can run two different scripts if necessary 
> >- resizegif.cgi and resizejpeg.cgi) and is a large image (<30K), but I 
> >want that down to 2-4K.
> >
> >2. the script should simply take an image, resize it, and then display 
> >it.  Ideally, the image should be within the boundaries of 120x120, or 
> >even better be able to tell if the image is portrait, landscape or square, 
> >and resize accordingly.  I have seen dozens of thumbnail gallery scripts, 
> >but nothing that does something as basic as what I want.  All the other 
> >scripts try to give me all sorts of HTML crap that I don't want.  I just 
> >want to perform the resize on a single image!!!! so I can place my own 
> >HREF tags around it!!!
-------------- next part --------------
#!/usr/bin/perl

use GD;
use CGI qw/:standard/;

# requires trailing slash..
use constant BASE_PATH => "/home/li/";

# resize the image to within these proportions
use constant RESIZE_WIDTH => 100;
use constant RESIZE_HEIGHT => 100;

if (-e BASE_PATH . param ('file'))
{
	my $im = imageResized (BASE_PATH . param ('file'),
		RESIZE_WIDTH, RESIZE_HEIGHT);

	print header ('image/jpeg');
	print $im->jpeg;
}

sub imageResized
{
	my ($file, $x, $y) = @_[0..2];

	my $im = GD::Image->newFromJpeg ($file);
	my ($im_x, $im_y) = $im->getBounds ();

	# solve for x
	if ($im_y > $im_x)
	{
		$x = ($y * $im_x) / $im_y;
	} # solve for y
	else
	{
		$y = ($x * $im_y) / $im_x;
	}
	
	my $out_im = new GD::Image ($x, $y);
	
	
	$out_im->copyResized ($im, 0, 0, 0, 0, $x, $y, $im_x, $im_y);

	return $out_im;
}


More information about the Phoenix-pm mailing list