...

View Full Version : could not output resize image



kamkam
02-29-2012, 08:27 AM
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


<?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


<?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($filename)==IMAGETYPE_JPEG)
header('Content-Type: image/jpeg');
else if(exif_imagetype($filename)==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($filename)==IMAGETYPE_JPEG)
imagejpeg($image_p, null, 100);
else if(exif_imagetype($filename)==IMAGETYPE_GIF)
imagegif($image_p, null, 100);

?>

Fou-Lu
02-29-2012, 01:50 PM
Check your error logs; does it show any problems with the calls to exif functions? Make sure you are testing with a jpg as well, this won't work with gif.

kamkam
02-29-2012, 09:00 PM
i put the "http://www.xxxx.com/account/display_thread_image.php?thread_photo_91Winter Leaves.jpg" into browser, and i have the warning;
Fatal error: Call to undefined function exif_imagetype()


but it is builded in fuction?

Fou-Lu
02-29-2012, 10:24 PM
Not exactly; exif is an external package provided with the original source code. Its available, but has to be enabled.
You need to contact your host in order to enable the exif functionality, or if its your own machine you can configure php on linux adding the --enable-exif, or by configuring PHP.ini in windows to allow php_mbstring.dll and php_exif.dll. The installation doc does indicate that mbstring MUST be available before exif, so it has to be moved up in the ini file.

getimagesize returns its guestimate of the file based on extension under the third offset. Will use the same constants you have here. An alternative is to open the file and scan in the header to determine the filetype, but that takes some knowledge of filestructures and how to implement them in PHP. Types are usually easy as they are represented by clear text (JFIF for example), but some are more complicated in how the are presented (png I think is right at the start of the file, but jpeg's I think are further in).

kamkam
03-01-2012, 02:40 AM
Thanks a lot, the host have enable the fuction for me already.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum