[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [cobalt-users] RE: Image Magick or NetPBM on RaQ4i
- Subject: Re: [cobalt-users] RE: Image Magick or NetPBM on RaQ4i
- From: "Ng Chern Ann" <chernann@xxxxxxxxxxxxxxx>
- Date: Mon Apr 22 06:27:01 2002
- List-id: Mailing list for users to share thoughts on Cobalt products. <cobalt-users.list.cobalt.com>
> > Message: 11
> > From: "Si Watts" <simon@xxxxxxxxxxx>
> > To: <cobalt-users@xxxxxxxxxxxxxxx>
> > Date: Sun, 21 Apr 2002 10:50:25 +0100
> > Subject: [cobalt-users] Image Magick or NetPBM on RaQ4i
> > Reply-To: cobalt-users@xxxxxxxxxxxxxxx
> >
> > a number of the projects I'm working on at the moment require
> > me to be able
> > to automatically manipulate images once they've been uploaded via PHP,
> > specifically I need to have them saved to a preset width and
> > duplicated in
> > thumbnail form, then the image details loaded into a MySQL db
> > (that bit
> > isn't exactly a problem).
> > The GDLib appears to not have the ficility to resize and so after much
> > research I've fallen onto 2 options: ImageMagick or NetPBM.
The GDLib can indeed resize, and GD 2.0 can do so in 24bit with bicubic and
other filters. This is a function I modified to do quick thumbnailing, but
there's no reason it cannot be used to do normal resizing. However, you
should use GD2.0 if you intend to do resizing of large images or the image
quality loss may be unacceptable.
<?
function thumbnail ($sourcefile, $targetfile, $width)
{
$jpegqual=50; //quality to save at, as a percent of 100.
$dest_x=$width;
/* Get the dimensions of the source picture */
$picsize=@getimagesize("$sourcefile");
if ($picsize==0)
{
return ("Either the image does not exist or the external host is
redirecting me. Sorry, I can't make a thumbnail! Perhaps you could
<b>upload</b> the picture directly instead?");
}
switch ( $picsize[2] ) {
case 0:
break;
case 1:
$imagetype="gif";
break;
case 2:
$imagetype="jpg";
break;
case 3:
$imagetype="png";
break;
}
$source_x = $picsize[0];
$source_y = $picsize[1];
$ratio = $dest_x/$source_x;
$dest_y= $source_y*$ratio;
if ($imagetype=="jpg")
$source_id = imageCreateFromJPEG("$sourcefile");
elseif ($imagetype=="gif")
$source_id = imageCreateFromGIF("$sourcefile");
elseif ($imagetype=="png")
$source_id = imageCreateFromPNG("$sourcefile");
/* Create a new image object (not neccessarily true colour) */
$target_id=imagecreate($dest_x, $dest_y);
//$targe_id=imagecreatetruecolor($dest_x,$dest_y);
/* Resize the original picture and copy it into the just created image
object. Because of the lack of space I had to wrap the parameters to
several lines. I recommend putting them in one line in order keep your
code clean and readable */
$target_pic=imagecopyresized($target_id,$source_id,
0,0,0,0,
$dest_x,$dest_y,
$source_x,$source_y);
/* Create a jpeg with the quality of "$jpegqual" out of the
image object "$target_pic".
This will be saved as $targetfile */
imagejpeg ($target_id,"$targetfile",$jpegqual);
}
?>