xyn Posted September 23, 2007 Share Posted September 23, 2007 Hey; I've been trying to get my thumbnail script to work. There are no errors produced, however the thumbnail isnt being created, the dimentions are the same as the original image. I was hoping for advise on where the problem is, and how to get around it; my code: <?php include_once($_SERVER['DOCUMENT_ROOT']."/config.inc.php"); $img_base = $_SERVER['DOCUMENT_ROOT']."/images/uploads/"; $max_width = base64_decode(Secure($_GET['w'])); $max_height = base64_decode(Secure($_GET['h'])); $image_file = base64_decode(Secure($_GET['s'])); $image_path = $img_base.$image_file; $img = null; $ext = strtolower(end(explode('.', $image_path))); if($ext == 'jpg' || $ext == 'jpeg') { $img = @imagecreatefromjpeg($image_path); } elseif($ext == 'png') { $img = @imagecreatefrompng($image_path); } elseif($ext == 'gif') { $img = @imagecreatefrompng($image_path); } if($img) { $width = imagesx($img); $height = imagesy($img); $scale = min($max_width/$width, $max_height/$height); if ($scale & 1) { $new_width = ceil($scale * $width); $new_height = ceil($scale * $height); $tmp_img = imagecreatetruecolor($new_width, $new_height); imagecopyresized($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height); imagedestroy($img); $img = $tmp_img; } } /* if(!$img) { #NO IMAGE _ CREATE _ ERROR _ IMAGE } */ header("Content-type: image/jpeg"); imagejpeg($img); ?> The image code: image_thumb.php?s=NDg4MTNiOWU5MDY2YTFkOTQ0YjBiNTk4NDhiMTYxYjhmNGM5MGE1ZjJiNzViMzAwY2I5N2RlMTEzMmIzNTczYmQ0ZjE5MmIxLnBuZw==&w=MTAw&h=OTg= Quote Link to comment https://forums.phpfreaks.com/topic/70343-thumbnail-image/ Share on other sites More sharing options...
xyn Posted September 23, 2007 Author Share Posted September 23, 2007 OK; I narrowed the error down a little: if($img) { $width = imagesx($img); $height = imagesy($img); $scale = min(ceil($max_width/$width), ceil($max_height/$height)); if ($scale & 1) { $new_width = ceil($scale * $width); $new_height = ceil($scale * $height); die($new_width."x".$new_height); $tmp_img = imagecreatetruecolor($new_width, $new_height); imagecopyresized($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height); $img = $tmp_img; } } $scale returns "1" which means its multiplying the current W/H by 1 ie why it doesnt change the size. any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/70343-thumbnail-image/#findComment-353384 Share on other sites More sharing options...
BlueSkyIS Posted September 23, 2007 Share Posted September 23, 2007 what are the values for $max_width and $max_height? Quote Link to comment https://forums.phpfreaks.com/topic/70343-thumbnail-image/#findComment-353465 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.