A good image scaling program?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
   Can anyone recommend a good image scaling program for PHP 4.  What
I'm really looking for is just a function that takes an image file and
a width to which to scale the image and outputs the scaled image.

I am grateful for anyone's recommendations, - Dave

Re: A good image scaling program?

I noticed that Message-ID:
contained the following:

Quoted text here. Click to load it

If you use the GD functions I'm not sure if  there's a pre written
function that does it all.

First you get the dimensions of the uploaded image.
You need to derive the new image height by some simple maths

new height = (oldheight/oldwidth)*new width

Then use imagecopyresampled to create the new image.

Lots of code examples about.
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker /

Re: A good image scaling program?

D. Alvarado wrote:
Quoted text here. Click to load it
$src and $tgt are absolute paths to the source file and new image.
$size will be the maximum dimension (either width or height) of the
reuslting rescaled image.
If size isnt given, it will be 150 pixels.

function createthumb ($src,$tgt,$size=150) {
     // create new thumbnail !                
     $src_img = imagecreatefromjpeg($src);
     if ($src_img) {
       // calc portrait or landscape
       if (imagesx($src_img) < imagesy($src_img))
           $scale = imagesy($src_img) /$size;
       else $scale = imagesx($src_img) /$size;
       // calc thumbnail dimensions    
       $new_w = round(imagesx($src_img)/$scale);
       $new_h = round(imagesy($src_img)/$scale);
       // create empty image of correct size & copy/resize image into it
       $dst_img = imagecreatetruecolor($new_w,$new_h);
       // save thumbnail to file
       imagejpeg($dst_img, $tgt);
       else print "<div class=error>failed to open $src</div>";

Re: A good image scaling program?

D. Alvarado wrote:

Quoted text here. Click to load it

If you have imagemagick installed on the server that's an easy way to go.
There's also the GD library which may or may not be installed into PHP.

The GD functions are in the manual at http://www.php.net/gd

Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com /

Re: A good image scaling program?

"D. Alvarado" wrote:
Quoted text here. Click to load it

Try hotscripts.com.  But that's also pretty easy to write (at least for JPG and
PNG) using the GD library.

Shawn Wilson

Site Timeline