Jump to content

header("Content-Type: image.jpeg") not working


Recommended Posts

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.