Hello!
This script is driving me crazy! 😕
I'm retreving fullsize images from a db and trying to return them into a table as thumbnails.
$image_path echos the correct path to the image but $thumbnail always echos 1.
Thanks for you help! 🙂
<?php
do {
// Constants
define(MAX_WIDTH, 300);
define(MAX_HEIGHT, 300);
//Get image
$image_path = $row_rs_images['image_path'];
// Load image
$img = null;
$ext = strtolower(end(explode('.', $image_path)));
if ($ext == 'jpg' || $ext == 'jpeg') {
$img = @imagecreatefromjpeg($image_path);
} else {
echo "This is not a jpeg image";
exit;
}
// If an image was successfully loaded, test the image for size
if ($img) {
// Get image size and scale ratio
$width = imagesx($img);
$height = imagesy($img);
$scale = min(MAX_WIDTH/$width, MAX_HEIGHT/$height);
// If the image is larger than the max shrink it
if ($scale < 1) {
$new_width = floor($scale*$width);
$new_height = floor($scale*$height);
// Create a new temporary image
$tmp_img = imagecreatetruecolor($new_width, $new_height);
// Copy and resize old image into new image
imagecopyresized($tmp_img, $img, 0, 0, 0, 0,
$new_width, $new_height, $width, $height);
imagedestroy($img);
$img = $tmp_img;
}
}
$thumbnail = imagejpeg($img, '0' ,'100');
echo '<table width="65%" border="1" cellspacing="0" cellpadding="3">
<tr>
<td width="31%"><div align="center"><img src='. $thumbnail. '/>
<td width="68%"> <br /><br />
</td></td>
</tr>
</table>
<p> </p>';
} while ($row_rs_images = mysql_fetch_assoc($rs_images));
?>