Connecting Tech Pros Worldwide Forums | Help | Site Map

A good image scaling program?

D. Alvarado
Guest
 
Posts: n/a
#1: Jul 17 '05
Hello,
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

Chris Hope
Guest
 
Posts: n/a
#2: Jul 17 '05

re: A good image scaling program?


D. Alvarado wrote:
[color=blue]
> Hello,
> 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[/color]

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/
Geoff Berrow
Guest
 
Posts: n/a
#3: Jul 17 '05

re: A good image scaling program?


I noticed that Message-ID:
<9fe1f2ad.0411041921.7928dd7c@posting.google.com > from D. Alvarado
contained the following:
[color=blue]
> 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.[/color]


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/
2metre
Guest
 
Posts: n/a
#4: Jul 17 '05

re: A good image scaling program?


D. Alvarado wrote:[color=blue]
> Hello,
> 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.[/color]
$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);
imagecopyresized($dst_img,$src_img,0,0,0,0,
$new_w,$new_h,
imagesx($src_img),imagesy($src_img));
imagedestroy($src_img);
// save thumbnail to file
imagejpeg($dst_img, $tgt);
imagedestroy($dst_img);
}
else print "<div class=error>failed to open $src</div>";
}
Shawn Wilson
Guest
 
Posts: n/a
#5: Jul 17 '05

re: A good image scaling program?


"D. Alvarado" wrote:[color=blue]
>
> 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.[/color]

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

Shawn
--
Shawn Wilson
shawn@glassgiant.com
http://www.glassgiant.com
Closed Thread