37 users online (1 members and 36 guests)  


  Results 1 to 12 of 12

Related

  1. Weird clickable area    Forum: CSS Forum
    Replies: 3
  2. Resizing Pictures    Forum: HTML Forum
    Replies: 2
  3. Window resizing, again    Forum: Javascript Forum
    Replies: 3
  4. Resizing a Window    Forum: Javascript Forum
    Replies: 2
  5. CIA news of the weird?    Forum: General Discussion
    Replies: 8
  1. #1
    Zamees's Avatar
    New User

    Status
    Offline
    Join Date
    Sep 2003
    Posts
    19

    Weird output on resizing images..

    This script works perfectly fine, but, i just used it for another page, and somehow, someway, it outputs a .bmp It takes a jpg or png file and resizes the image to create thumbnails on the fly. but how on earth does it output a .bmp
    I save that script in the same folder as my asp page and then call to it like this..
    <img src="x03/img.php?f(x03017.jpg) + h(100)" > and when I save as from the loaded webpage, it saves as file type .bmp... explanation please.

    Code:
    <?php
    
    // define the base image dir
    $base_img_dir = "./";
    
    // $QUERY_STRING =
    //  f(3c9b5fa6bc0fa)  img_file
    //  w(123|15%)        width of output
    //  h(123|10%)        height of output
    //  x(123)            max width of output
    //  y(123)            max height of output
    //  t(jpg|png|JPG)        type of output
    //  q(100)            quality of jpeg
    
    // find tags
    preg_match_all("/\+*(([a-z])\(([^\)]+)\))\+*/", $QUERY_STRING,
                    $matches, PREG_SET_ORDER);
    
    // empty array and set regular expressions for the check
    $tags = array();
    $check = array( "f" => "[^)+]+",
                    "w" => "[0-9]+%?",
                    "h" => "[0-9]+%?",
                    "x" => "[0-9]+",
                    "y" => "[0-9]+",
                    "t" => "jpg|png|JPG",
                    "q" => "1?[0-9]{1,2}" );
    
    
    // check tags and save correct values in array
    for ($i=0; $i<count($matches); $i++) {
        if (isset($check[$matches[$i][2]])) {
            if (preg_match('/^('.$check[$matches[$i][2]].')$/',
                   $matches[$i][3])) {
                $tags[$matches[$i][2]] = $matches[$i][3];
            }
        }
    }
    
    function notfound() {
        header("HTTP/1.0 404 Not Found");
        exit;
    }
    
    // check that filename is given
    if (!isset($tags["f"])) {
        notfound();
    }
    
    // check if file exists
    if (!file_exists($base_img_dir.$tags["f"])) {
        notfound();
    }
    
    // retrieve file info
    $imginfo = getimagesize($base_img_dir.$tags["f"]);
    
    // load image
    switch ($imginfo[2]) { 
        case 2:     // jpg
            $img_in = imagecreatefromjpeg($base_img_dir.$tags["f"]) or notfound();
            if (!isset($tags["t"])) {
                $tags["t"] = "jpg";
            }
            break;
        case 3:     // png
            $img_in = imagecreatefrompng($base_img_dir.$tags["f"]) or notfound();
            if (!isset($tags["t"])) {
                $tags["t"] = "png";
            }
            break;
        case 4:    // JPG
            $img_in = imagecreatefromjpeg($base_img_dir.$tags["f"]) or notfound();
            if (!isset($tags["t"])) {
                $tags["t"] = "JPG";
            }
            break;
        default:
            notfound();
    }
    
    // check for maximum width and height
    if (isset($tags["x"])) {
        if ($tags["x"] < imagesx($img_in)) {
            $tags["w"] = $tags["x"];
        }
    }
    if (isset($tags["y"])) {
        if ($tags["y"] < imagesy($img_in)) {
            $tags["h"] = $tags["y"];
        }
    }
    
    // check for need to resize
    if (isset($tags["h"]) or isset($tags["w"])) {
        // convert relative to absolute
        if (isset($tags["w"])) {
            if (strstr($tags["w"], "%")) {
                $tags["w"] = (intval(substr($tags["w"], 0, -1)) / 100) *
                              $imginfo[0];
            }
        }
        if (isset($tags["h"])) {
            if (strstr($tags["h"], "%")) {
                $tags["h"] = (intval(substr($tags["h"], 0, -1)) / 100) *
                              $imginfo[1];
            }
        }
    
        // resize
        if (isset($tags["w"]) and isset($tags["h"])) {
            $out_w = $tags["w"];
            $out_h = $tags["h"];
        } elseif (isset($tags["w"]) and !isset($tags["h"])) {
            $out_w = $tags["w"];
            $out_h = $imginfo[1] * ($tags["w"] / $imginfo[0]);
        } elseif (!isset($tags["w"]) and isset($tags["h"])) {
            $out_w = $imginfo[0] * ($tags["h"] / $imginfo[1]);
            $out_h = $tags["h"];
        } else {
            $out_w = $tags["w"];
            $out_h = $tags["h"];
        }
        
        // new image in $img_out
        $img_out = imagecreatetruecolor($out_w, $out_h);
        imagecopyresampled($img_out, $img_in, 0, 0, 0, 0, imagesx($img_out),
                   imagesy($img_out), imagesx($img_in), imagesy($img_in));
    } else {
        // no resize needed
        $img_out = $img_in;
    }
    
    // check for a given jpeg-quality, otherwise set to default
    if (!isset($tags["q"])) {
        $tags["q"] = 75;
    }
    
    // returning the image
    switch ($tags["t"]) {
        case "jpg":
            header("Content-type: image/jpeg");
            imagejpeg($img_out, "", $tags["q"]);
            exit;
        case "png":
            header("Content-type: image/png");
            imagepng($img_out);
            exit;
        case "JPG":
            header("Content-type: image/jpeg");
            imagejpeg($img_out, "", $tags["q"]);
            exit;
       default:
            notfound();
    }
    
    ?>

  2. #2
    Zamees's Avatar
    New User

    Status
    Offline
    Join Date
    Sep 2003
    Posts
    19
    Im thinking maybe IE has some default output for certain images that is BMP, anyone ever hear of that?

  3. #3
    HTML's Avatar
    Administrator

    Status
    Offline
    Join Date
    Aug 2000
    Posts
    3,445

    Follow HTML On Twitter Add HTML on Facebook Add HTML on Google+ Add HTML on Linkedin Visit HTML's Youtube Channel
    Quote Originally Posted by Zamees
    Im thinking maybe IE has some default output for certain images that is BMP, anyone ever hear of that?
    Since the script you provided is PHP which is a server side language, I would have to say that it is not an IE issue since the code is provided before it ever hits the browser.

    Unfortunately this is all I can offer on the subject.

    Dave

  4. #4
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    Try changing the the Content-type: to jpg instead of jpeg

    IE can be funny like that
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  5. #5
    HTML's Avatar
    Administrator

    Status
    Offline
    Join Date
    Aug 2000
    Posts
    3,445

    Follow HTML On Twitter Add HTML on Facebook Add HTML on Google+ Add HTML on Linkedin Visit HTML's Youtube Channel
    Something tells me there is a server module or setting that may be controlling this, but since I am not a server admin I cant think of what I am thinking of .

    If Deans idea does not produce the correct results try contacting your web host.

    Dave

  6. #6
    HTML's Avatar
    Administrator

    Status
    Offline
    Join Date
    Aug 2000
    Posts
    3,445

    Follow HTML On Twitter Add HTML on Facebook Add HTML on Google+ Add HTML on Linkedin Visit HTML's Youtube Channel

    I stand corrected

    It looks like it is an IE issue, http://support.microsoft.com/default.aspx?scid=kb;en-us;Q260650

    Dave

  7. #7
    Zamees's Avatar
    New User

    Status
    Offline
    Join Date
    Sep 2003
    Posts
    19
    Hey Dave,

    Thats gotta be what it is. Thanx for pointing out that article. It still strikes me as odd. Script works fine in one folder, but not in the other. Both are just folders which hold a few jpg's. I tried all the workarounds, short of typing in the direct address, which obviously would work. Thanx again Dave.

  8. #8
    Zamees's Avatar
    New User

    Status
    Offline
    Join Date
    Sep 2003
    Posts
    19
    Would a script like this take up too many resources on the server? My account was shut down for using a consistent 73% of server resources. This script was used many times, but It only loading 20 at a time per user. Not sure why it would bog anything down.

  9. #9
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    It would take more resources than most scripts, But 73% seems very high. is your host a paid host? I would expect to be able to run this on a paid host until I reached my bandwidth limit.

    Compared to something like a bulletin board, this script would use hardly any resources. I suggest your host checks its own setup.
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  10. #10
    Zamees's Avatar
    New User

    Status
    Offline
    Join Date
    Sep 2003
    Posts
    19
    Yea, I agree. It is paid. And they shut me down for 8 hours last night becuase i was cuasing server problems. The page gets viewed a lot though. I was displaying 20 thumbnails per page, and each thumbnail would be a call to the script. So in 5 days the script was viewed 296,000 times. But even so, would a 5kb file and 2kb picture files take up that many resources?

    Should I question them on this, or do the numbers now give reason for what they claimed?

  11. #11
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    Ah, yes it could. I didn't realise, but it sounds liek your not caching your thumbnails.

    Would it not be easier/simpler to create the thumbnail once? Then a small piece of code to check whether a cache exists and create it if it doesn't?
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  12. #12
    Zamees's Avatar
    New User

    Status
    Offline
    Join Date
    Sep 2003
    Posts
    19
    Yep, thats exactly what I've done. Took me all of yesterday, and its pretty rugged the way i got it working, but it works.



Tags for this Thread