|
Posted by Jim Michaels on 02/27/06 10:20
"seemore" <seemore@gbg.bg> wrote in message
news:1140877338.608310.230340@u72g2000cwu.googlegroups.com...
The script below resizes images. My problem is that
the output is not image ? output is ?PNG or ?GIF
................ Any idea how to fix my
script?
a lot of your problem is the misuse of urlencode() and your miscoding of
your URL. it's all flipped around. you should use urlencode() to encode
the filepath to your image *before* inserting it into the URL for thump.php.
then you should use urldecode() and stick the results in a variable.
Thanks!
Dag Eilertsen
'SCRIPT'
/**
* For instance,
thumb.php?img=http%3A%2F%2Fwww.google.com/images/logo.gif&width=200
*
*/
I corrected your URL there. --^^^^----------------------------^^^^^^
no & just & I gon't think the browser is is going to react
consistently across the board to the :// not being near the front. you
should use urlencode() before feeding that google path into thump.php.
that's what urlencode is for: for encoding stuff that needs to go into a
URL.
and then drop the urlencode later.
valid URI's are: http://www.ietf.org/rfc/rfc2396.txt
<scheme>://<authority><path>?<query>
( net_path | abs_path | rel_path ) [ "?" query ]
<scheme>:<scheme-specific-part>
and there are others I won't go into.
/**
* These define the maximum width and height of
* thumbnails. Edit these if wanted.
*/
$maxwidth = 100;
$maxheight = 150;
/**
* Path to your error image.
*/
$errorimg = '404.png';
I got rid of urlencode functions below...
$file_extension = substr($_GET['img'],
strrpos($_GET['img'], '.')+1);
switch(strtolower($file_extension)) {
case "gif": $content_type="image/gif"; break;
case "png": $content_type="image/png"; break;
case "bmp": $content_type="image/bmp"; break;
case "jpeg":
case "jpg": $content_type="image/jpg"; break;
case "img": $content_type="image/jpg"; break;
default: $content_type="image/png"; break;
}
header('Content-type: ' . $content_type);
$width = $_GET['width'];
if ($width == '')
$width = $maxwidth;
$height = $maxheight;
code change here:
//$blah = getimagesize(urldecode($_GET['img']));
//$type = $blah['mime'];
//$width_orig = $blah[0];
//$height_orig = $blah[1];
if (list($width_orig, $height_orig, $type, $attr) =
@getimagesize($_GET['img'])) {
if ($width && ($width_orig < $height_orig)) {
$width = ($height / $height_orig) * $width_orig;
} else {
$height = ($width / $width_orig) * $height_orig;
}
}
do this below:
$img=urldecode($_GET['image']);
// Resample
//$image_p = @imagecreatetruecolor($width, $height);
ini_set('memory_limit', '32M');
switch(strtolower($file_extension)) {
case "gif": $image = @imagecreatefromgif($img); break;
case "png": $image = @imagecreatefrompng($img); break;
case "bmp": $image = @imagecreatefromwbmp($img); break;
case "jpeg":
case "jpg": $image = @imagecreatefromjpeg($img]); break;
case "img": $image = @imagecreatefromjpeg($img]); break;
default: $image = @imagecreatefrompng($errorimg); break;
}
if (!$image) {
$image = imagecreatefrompng($errorimg);
imagepng($image);
} else {
$image_p = @imageCreateTrueColor($width, $height);
if (!$image_p) { $image_p = imageCreate($width, $height); }
@imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width,
$height,$width_orig, $height_orig);
// Output
switch(strtolower($file_extension)) {
/**
* Gif write on my hosting is not enabled, thus this oddity.
* Feel free to change it.
*/
case "gif": $imageoutput = imagejpeg($image_p); break;
case "png": $imageoutput = imagepng($image_p); break;
case "bmp": $imageoutput = imagewbmp($image_p); break;
case "jpeg":
case "jpg": $imageoutput = imagejpeg($image_p); break;
case "img": $imageoutput = imagejpeg($image_p); break;
default: $imageoutput = imagepng($image_p); break;
}
@imagedestroy($image_p);
@imagedestroy($image);
}
[Back to original message]
|