Reputation: 15673
I used a very simple code to resize image with PHP; but surprisingly it does not work for some images. The problem should be associated with imagecreatefromjpeg(), as it will generate a black image (which is of the background image).
$picture="test5.jpg";
$url="http://www.pokerpurist.com/uploadedImages/bettingpro/NewsImages/TN98553_Perla-Beltran.jpg";
list($width, $height) = getimagesize($url);
$new_height = $height / $width * 400;
$image_p = imagecreatetruecolor(400, $new_height);
$image = imagecreatefromjpeg($url);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, 400, $new_height, $width, $height);
imagejpeg($image_p, $picture);
echo "<img src='$picture' />";
This problem happens offen, and I included an example image. What is the problem with these images leading to this problem? It seems to be a normal JPG image.
By the way, is it the simplest and most efficient way to resize image with PHP/GD2?
Upvotes: 0
Views: 992
Reputation: 683
@By the way, is it the simplest and most efficient way to resize image with PHP/GD2?
Use Asido: PHP Image Processing Solution
Asido supports the following features:
If you can't access Asido website, you can download Asido from SourceForge.net
Upvotes: 2
Reputation: 4177
Your example image is a PNG, not JPEG. You probably need to put some detection code in place...
Edit: exif-imagetype or ImageMagick might be of some use.
Upvotes: 2