Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8440133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:12:09+00:00 2026-06-10T08:12:09+00:00

The script provided below res.php is designed to scale images that are then used

  • 0

The script provided below “res.php” is designed to scale images that are then used in HEADER css of the html page. The images are called depending on the “CID” (Club ID). Each Club has there information stored in the database including one called club_header. The club_header is a VARCHAR that stores absolute image location (file-system or web). The “res.php” function is to call image and output it to browser as well as re-size the image to whatever the settings are set for. By default the settings are 960 x 200.

However do to some reason the script is not doing what it has to be and outputs a broken image instead. What may the problem be with the code?

Some server + php info if needed

Server: Apache v2.2.21, PHP v5.3.8, SQL v5.5.16, GD v2.0.34

PHP.ini: max_execution_time = 300, max_input_time = 60, memory_limit = 208M, post_max_size = 24M

“res.php” source-code

require("php/db.class.php");

function scaleImageFileToBlob($file) {

    $file = $_GET['cid'];

    $query = mysql_query("SELECT * FROM clubs WHERE club_id = '".$_GET['cid']."'");
    $obj = mysql_fetch_array($query);
    $photoObj = $obj['club_header'];

    $source_pic = $photoObj;
    $max_width = 960;
    $max_height = 200;

    list($width, $height, $image_type) = getimagesize($file);

    switch ($image_type)
    {
        case 1: $src = imagecreatefromgif($file); break;
        case 2: $src = imagecreatefromjpeg($file);  break;
        case 3: $src = imagecreatefrompng($file); break;
        default: return '';  break;
    }

    $x_ratio = $max_width / $width;
    $y_ratio = $max_height / $height;

    if( ($width <= $max_width) && ($height <= $max_height) ){
        $tn_width = $width;
        $tn_height = $height;
        }elseif (($x_ratio * $height) < $max_height){
            $tn_height = ceil($x_ratio * $height);
            $tn_width = $max_width;
        }else{
            $tn_width = ceil($y_ratio * $width);
            $tn_height = $max_height;
    }

    $tmp = imagecreatetruecolor($tn_width,$tn_height);

    /* Check if this image is PNG or GIF, then set if Transparent*/
    if(($image_type == 1) OR ($image_type==3))
    {
        imagealphablending($tmp, false);
        imagesavealpha($tmp,true);
        $transparent = imagecolorallocatealpha($tmp, 255, 255, 255, 127);
        imagefilledrectangle($tmp, 0, 0, $tn_width, $tn_height, $transparent);
    }
    imagecopyresampled($tmp,$src,0,0,0,0,$tn_width, $tn_height,$width,$height);

    /*
     * imageXXX() only has two options, save as a file, or send to the browser.
     * It does not provide you the oppurtunity to manipulate the final GIF/JPG/PNG file stream
     * So I start the output buffering, use imageXXX() to output the data stream to the browser, 
     * get the contents of the stream, and use clean to silently discard the buffered contents.
     */
    ob_start();

    switch ($image_type)
    {
        case 1: imagegif($tmp); break;
        case 2: imagejpeg($tmp, NULL, 100);  break; // best quality
        case 3: imagepng($tmp, NULL, 0); break; // no compression
        default: echo ''; break;
    }

    $final_image = ob_get_contents();

    ob_end_clean();

    return $final_image;

}

echo scaleImageFileToBlob($file);

Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T08:12:10+00:00Added an answer on June 10, 2026 at 8:12 am

    You might need to send the correct header before the image output, such as

    header('Content-Type: image/png');
    
    header('Content-Type: image/jpeg');
    
    header('Content-Type: image/gif');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I personally know limited PHP, however I have a script provided by another, that
whenever I've used Ajax, I've used asp.net Ajax update panel and script manager provided
I have a script that somebody from SO kindly provided to solve an issue
I was using the below code provided by Google for Google Analytics. <script type=text/javascript>
the html looks like below or you can find it here http://www.vbulletin.org/forum/index.php <!-- login
So I have a comments script I've written in Codeigniter that uses PHP and
Based on the solution provided in Test for existence of perl mod inside script
I'm looking to create a PHP script where, a user will provide a link
Script link on master page: <head runat=server> <script src=<%=ConfigurationManager.AppSettings[ApplicationURL].ToString()%>Scripts/jquery-1.7.2.js type=text/javascript language=javascript></script> </head> Default.aspx page
PHP script to read in user action requests and parse them to their components.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.