Reputation: 202
I'm using the GD library to rescale jpeg images, so that the resulting image has 100px width. I use the following code:
$image = imagecreatefromjpeg('images/Image1.jpg');
$imageScaled = imagescale($image, 100);
// Save the image as 'simpletext.jpg'
imagejpeg($image, 'simpletext.jpg',90);
// Free up memory
imagedestroy($image);
The code appears to work correctly. For example if I use a 391x291 pixel image, I get a smaller image consistent with the change. The thing is that if I try to get info about the size of the (resized) image via my OS (Windows 8) or via PHP:
$imageSize = getimagesize('simpletext.jpg');
echo 'Image size: ' . $imageSize[0] . 'x' . $imageSize[1];
I get that the image dimension still is 391x291 pixel. Why is that?
Upvotes: 0
Views: 2859
Reputation: 5326
You are saving the original image instead of the scaled one. Fix your code to do this:
imagejpeg($imageScaled, 'simpletext.jpg',90);
Upvotes: 5