krash11554 Posted September 12, 2012 Share Posted September 12, 2012 Hello all i have made a thumnail function and i think the function is working but it has to do with header. here is the function function create_thumbnail($path,$save,$width,$height){ $info = getimagesize($path); $size = array($info[0], $info[1]); if ($info['mime'] == 'image/png'){ $src = imagecreatefrompng($path); }elseif($info['mime'] == 'image/jpeg'){ $src = imagecreatefromjpeg($path); }elseif($info['mime'] == 'image/gif'){ $src = imagecreatefromgif($path); }else{ return false; } $thumb = imagecreatetruecolor($width,$height); $src_aspect = $size[0] / $size[1]; $thumb_aspect = $width / $height; if($src_aspect < $thumb_aspect){ //narrower $scale = $width / $size[0]; $new_size = array($width, $width / $src_aspect); $src_pos = array(0, ($size[1] * $scale - $height) / $scale / 2 ); }elseif($src_aspect > $thumb_aspect){ //wider $scale = $height / $size[1]; $new_size = array($height * $src_aspect, $height); $src_pos = array(($size[0] * $scale - $height) / $scale / 2,0); }else{ //same shape $new_size = array($width, $height); $src_pos = array(0,0); } $new_size[0] = max($new_size[0], 1); $new_size[1] = max($new_size[1], 1); imagecopyresampled($thumb, $src, 0,0, $src_pos[0], $src_pos[1], $new_size[0], $new_size[1],$size[0],$size[1]); if($save === false){ return imagejpeg($thumb); }else{ return imagejpeg($thumb, $save); } } here is the top of my php file where the header is . include "{$_SERVER['DOCUMENT_ROOT']}/garage/core/init.php"; protect_page(); header('Content-Type: image/jpeg'); include "{$_SERVER['DOCUMENT_ROOT']}/garage/includes/overall/overallheader.php"; create_ the create_thumbnail("kyle.jpg",false,100,100); would be further down in the code. i am running on localhost with iis by the way thanks Quote Link to comment https://forums.phpfreaks.com/topic/268312-headercontent-type-imagejpeg-not-working/ Share on other sites More sharing options...
requinix Posted September 13, 2012 Share Posted September 13, 2012 Are you trying to output something besides the raw image data? That overallheader.php sound suspicious. Don't. Just the image. Quote Link to comment https://forums.phpfreaks.com/topic/268312-headercontent-type-imagejpeg-not-working/#findComment-1377474 Share on other sites More sharing options...
krash11554 Posted September 13, 2012 Author Share Posted September 13, 2012 Yea i think your asking like outputting html?? and if so, yes im trying to output html and the image. Quote Link to comment https://forums.phpfreaks.com/topic/268312-headercontent-type-imagejpeg-not-working/#findComment-1377481 Share on other sites More sharing options...
scootstah Posted September 13, 2012 Share Posted September 13, 2012 You can't output anything else except for the image. Content-Type: image/jpeg means the page will be an image. HTML is not an image. Quote Link to comment https://forums.phpfreaks.com/topic/268312-headercontent-type-imagejpeg-not-working/#findComment-1377485 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.