Hi;
I got a problem to output resize image after i check the type of image.
Could anyone help me, thanks.
The test_1.php has not problem to output image, but the test_2.php could not output image.
test_1.php
test_2.php
I got a problem to output resize image after i check the type of image.
Could anyone help me, thanks.
The test_1.php has not problem to output image, but the test_2.php could not output image.
test_1.php
Code:
<?php
$image=$_GET['image'];
// The file
$filename = '../images/thread_images/'. $image;
// Set a maximum height and width
$width = 200;
$height = 200;
// Content type
header('Content-Type: image/jpeg');
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);
$ratio_orig = $width_orig/$height_orig;
if ($width/$height > $ratio_orig) {
$width = $height*$ratio_orig;
} else {
$height = $width/$ratio_orig;
}
// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// Output
imagejpeg($image_p, null, 100);
?>
test_2.php
Code:
<?php
$image=$_GET['image'];
// The file
$filename = '../images/thread_images/'. $image;
// Set a maximum height and width
$width = 200;
$height = 200;
// Content type
if(exif_imagetype($image)==IMAGETYPE_JPEG)
header('Content-Type: image/jpeg');
else if(exif_imagetype($image)==IMAGETYPE_GIF)
header('Content-Type:image/gif');
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);
$ratio_orig = $width_orig/$height_orig;
if ($width/$height > $ratio_orig) {
$width = $height*$ratio_orig;
} else {
$height = $width/$ratio_orig;
}
// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// Output
if(exif_imagetype($imagepath)==IMAGETYPE_JPEG)
imagejpeg($image_p, null, 100);
else if(exif_imagetype($imagepath)==IMAGETYPE_GIF)
imagegif($image_p, null, 100);
?>