Denne kode kan, og som du nok kan læse er den lavet af XyborX
<?php
/*************************************************************\* Image resizer, version 2.1 - May10,2003 *
* Returns true on success, false if there are errors *
* If destination file is specified, resized picture will be *
* saved with the specified name. Else, it is shown to browser *
* Version 2: Now scales both up and down, still preserving *
* aspect ratio, and it accepts not only jpeg, but *
* also png and possibly bmp *
* Version 2.1: Genereal optimization and bugfixing. *
* No longer requires GD-lib to be >=2.0.1 *
}*************************************************************{
* Created by XyborX (www.xyborx.dk) *
* Feel free to use, modify and distribute, without profit. *
* I cannot be held liable for any damage this script might do *
\\*************************************************************/
function imageresize($sourcefile,$maxwidth,$maxheight,$destinationfile=false)
{
$types=Array();
$types[1]='gif';
$types[2]='jpeg';
$types[3]='png';
$types[6]='wbmp';
list($width,$height,$type)=getimagesize($sourcefile);
$type_name=$types[$type];
$imagecreatefromtype='imagecreatefrom'.$type_name;
$imagetype='image'.$type_name;
if(!function_exists($imagecreatefromtype) || !function_exists($imagetype))
{
return false;
}
if($img_src=$imagecreatefromtype($sourcefile))
{
$ratio_height=$maxheight/$height;
$ratio_width=$maxwidth/$width;
$ratio=min($ratio_width,$ratio_height);
$newwidth=$width*$ratio;
$newheight=$height*$ratio;
if(function_exists('imagecreatetruecolor'))
{
$img_dst=imagecreatetruecolor($newwidth,$newheight);
}
elseif(function_exists('imagecreate'))
{
$img_dst=imagecreate($newwidth,$newheight);
}
else
{
return false;
}
if(function_exists('imagecopyresampled'))
{
imagecopyresampled($img_dst, $img_src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
//imagedestroy($img_src);
//imagedestroy($img_dst);
}
elseif(function_exists('imagecopyresized'))
{
imagecopyresized($img_dst, $img_src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
//imagedestroy($img_src);
//imagedestroy($img_dst);
}
else
{
imagedestroy($img_src);
imagedestroy($img_dst);
return false;
}
if($destinationfile==false)
{
header('Content-type: '.image_type_to_mime_type($type));
$imagetype($img_dst);
}
else
{
$imagetype($img_dst,$destinationfile);
}
imagedestroy($img_src);
imagedestroy($img_dst);
return true;
}
else
{
return false;
}
}
?>
imageresize("filen der oploades", "max bredde", "max højde", "filen flyttes til mappe + navn");
"filen flyttes til mappe + navn": eks. nyheder/billeder/billed1.jpg