Page 1 of 1
Resizing JPG / JPEG
Posted: Thu Nov 18, 2004 8:11 pm
by Ambush Commander
Are there any functions in PHP used for resizing JPG / JPEG images (I found some that adjusted image quality, but not for resizing? How about for GIF?
And if there isn't, are there any good ways to generate thumbnails? (Supposedly JPEG has embedded thumbnails)
Posted: Thu Nov 18, 2004 8:21 pm
by John Cartwright
I would recommend you take a look at the GD libraries found here [php_man]gd[/php_man]
Posted: Fri Nov 19, 2004 5:54 am
by emperor
GD can be slightly complicated to get used to, but the most common way to resize JPEGs using it is like this
Code: Select all
<?php
$src = ImageCreateFromJPEG ($src_filename);
$width = ImageSx ($src);
$height = ImageSy ($src);
$x = $new_width;
$y = $new_height;
$dst = ImageCreateTrueColor ($x, $y);
ImageCopyResampled ($dst, $src, 0, 0, 0, 0, $x, $y, $width, $height);
ImageJPEG ($dst, $dst_filename); // or ImagePNG
DestroyImage ($dst);
?>
Like Phenom says though, it's best to read up on GD anyway so you know exactly what the functions are doing.
Posted: Fri Nov 19, 2004 4:17 pm
by Ambush Commander
Okay, thanks. Why did they name them GD? Doesn't sound like pictures at all... (don't answer that question, I think it's like Graphic _)
Now the only problem I have is installing the GD libraries on my system...
Hur. I still haven't gotten Mysql to work either,
Posted: Fri Nov 19, 2004 5:14 pm
by MarK (CZ)
Ambush Commander wrote:Okay, thanks. Why did they name them GD? Doesn't sound like pictures at all... (don't answer that question, I think it's like Graphic _)
What does "gd" stand for?
In gd 1.0, it stood for "gif draw." After the Unisys patent on the LZW compression used in GIF came to light and GIF support was dropped, it did not officially stand for anything, but let's just say "graphics draw" and leave it at that. (GIF support is back, thanks to the expiration of the patent, but gd can draw much more than GIFs.)