ok code coming, my solution as of now, is call the script from the img src and then set the height and border to 0

then when i call it from the folder it loads nicely.
The resize image script
As stated above called to like so... <img src=img.php?f(filename.jpg)>
Code: Select all
<?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;
}
$new_image = $base_img_dir."t_".$tagsї"f"];
// returning the image
switch ($tagsї"t"]) {
case "jpg":
header("Content-type: image/jpeg");
imagejpeg($img_out, $new_image);
imagejpeg($img_out, "");
exit;
case "png":
header("Content-type: image/png");
imagepng($img_out, "");
exit;
case "JPG":
header("Content-type: image/jpeg");
imagejpeg($img_out, $new_iamge);
exit;
default:
notfound();
}
?>