Reply to GD can't create image....

Your name:

Reply:


Posted by seemore on 02/25/06 16:22

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?

Thanks!
Dag Eilertsen

'SCRIPT'

/**
* For instance,
thumb.php?img=http://www.google.com/images/logo.gif&width=200
*
*/


/**
* 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';



$file_extension = substr(urlencode($_GET['img']),
strrpos(urlencode($_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;

//$blah = getimagesize($_GET['img']));
//$type = $blah['mime'];
//$width_orig = $blah[0];
//$height_orig = $blah[1];

if (list($width_orig, $height_orig, $type, $attr) =
@getimagesize(urlencode($_GET['img']))) {

if ($width && ($width_orig < $height_orig)) {
$width = ($height / $height_orig) * $width_orig;
} else {
$height = ($width / $width_orig) * $height_orig;
}
}



// Resample
//$image_p = @imagecreatetruecolor($width, $height);
ini_set('memory_limit', '32M');
switch(strtolower($file_extension)) {
case "gif": $image = @imagecreatefromgif($_GET['img']); break;
case "png": $image = @imagecreatefrompng($_GET['img']); break;
case "bmp": $image = @imagecreatefromwbmp($_GET['img']); break;
case "jpeg":
case "jpg": $image = @imagecreatefromjpeg($_GET['img']); break;
case "img": $image = @imagecreatefromjpeg($_GET['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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация