GumSlone
Administrator Principal · 1,690 posts
11 years ago
#2
found some old simple script that i have used long ago
<?php
if( is_array($_REQUEST) )
{
while( list($k, $v) = each($_REQUEST) )
{
if( is_array($_REQUEST[$k]) )
{
while( list($k2, $v2) = each($_REQUEST[$k]) )
{
$$k[$k2] = addslashes($v2);
}
@reset($_REQUEST[$k]);
}
else
{
$$k = addslashes($v);
}
}
@reset($_REQUEST);
}
$size = getimagesize($filename);
if(($size['mime'] == 'image/gif'||$size['mime'] == 'image/jpeg'||$size['mime']=='image/png')&& !empty($filename))
{
if($height>500)$height= 500;
if($width>500)$width= 500;
if(!$height)$height= 128;
if(!$width)$width= 128;
header('Content-type: image/jpeg');
$width_orig=$size[0];
$height_orig=$size[1];
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);
if($size['mime']=="image/gif")$image = imagecreatefromgif($filename);
if($size['mime']=="image/jpeg")$image = imagecreatefromjpeg($filename);
if($size['mime']=="image/png")$image = imagecreatefrompng($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// Output
imagejpeg($image_p, null, 80);
ImageDestroy ($image_p);
}
else
{
}
?>
usage example : image.php?filename=image/dir/pic.jpg&width=300&height=300