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)
Resizing JPG / JPEG
Moderator: General Moderators
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
GD can be slightly complicated to get used to, but the most common way to resize JPEGs using it is like this
Like Phenom says though, it's best to read up on GD anyway so you know exactly what the functions are doing.
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);
?>- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
- MarK (CZ)
- Forum Contributor
- Posts: 239
- Joined: Tue Apr 13, 2004 12:51 am
- Location: Prague (CZ) / Vienna (A)
- Contact:
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.)