Results 1 to 12 of 12
Related
-
Weird clickable area Forum: CSS Forum
Replies: 3 -
Resizing Pictures Forum: HTML Forum
Replies: 2 -
Window resizing, again Forum: Javascript Forum
Replies: 3 -
Resizing a Window Forum: Javascript Forum
Replies: 2 -
CIA news of the weird? Forum: General Discussion
Replies: 8
-
10-03-2003, 03:42 AM #1
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(); } ?>
-
10-04-2003, 03:24 AM #2
Im thinking maybe IE has some default output for certain images that is BMP, anyone ever hear of that?
-
10-04-2003, 09:16 AM #3
Originally Posted by Zamees
Unfortunately this is all I can offer on the subject.
Dave
-
10-04-2003, 12:46 PM #4
Try changing the the Content-type: to jpg instead of jpeg
IE can be funny like thatIf one of our members helps you, please click theicon to add to their reputation!
No support via email or private message - use the forums!
Before you ask, have you Searched?
-
10-04-2003, 05:02 PM #5
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
-
10-04-2003, 09:23 PM #6
I stand corrected
It looks like it is an IE issue, http://support.microsoft.com/default.aspx?scid=kb;en-us;Q260650
Dave
-
10-05-2003, 10:19 AM #7
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.
-
10-06-2003, 06:25 AM #8
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.
-
10-06-2003, 11:39 AM #9
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 theicon to add to their reputation!
No support via email or private message - use the forums!
Before you ask, have you Searched?
-
10-06-2003, 01:26 PM #10
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?
-
10-06-2003, 03:46 PM #11
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 theicon to add to their reputation!
No support via email or private message - use the forums!
Before you ask, have you Searched?
-
10-07-2003, 06:42 AM #12
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.
Cloudjiffy- PaaS for Developers
10-05-2020, 12:30 AM in Web Hosting Forum