<?
...
$size=getimagesize($filenamex);
if (..big file, resize and store..) {
$isrc=imagecreatefromjpeg($filenamex);
$s0=$size[0];
$s1=$size[1];
if ($s0>$maxwi) {
$s1=(int)$s1*$maxwi/$s0;
$s0=$maxwi;
}
if ($s1>$maxhe) {
$s0=(int)$s0*$maxhe/$s1;
$s1=$maxhe;
}
$idst=imagecreatetruecolor($s0,$s1);
fastimagecopyresampled($idst,$isrc,0,0,0,0,$s0,$s1,$size[0],$size[1]);
imagejpeg($idst,$uploadfile,90);
imagedestroy($isrc);
imagedestroy($idst);
$size[0]=$s0;
$size[1]=$s1;
}
if (!dbchange('INSERT INTO tttimage values (....)')) {
setmessage('Fel vid registrering av bild<br><br>');
header('location:loadpicture.php');
}
// make downscaled copies
if (strpos(strtoupper($ffname),'.JPG')>0) {
if ($size[0]>200) {
$w=130;
$isrc=imagecreatefromjpeg('../pics/'.$ffname);
$h=(int)$w*$size[1]/$size[0];
$idst=imagecreatetruecolor($w,$h);
imagecopyresampled($idst,$isrc,0,0,0,0,$w,$h,$size[0],$size[1]);
imagejpeg($idst,'../pics'.$w.'/'.$ffname,90);
imagedestroy($idst);
}
if ($size[0]>300) {
$w=220;
$h=(int)$w*$size[1]/$size[0];
$idst=imagecreatetruecolor($w,$h);
imagecopyresampled($idst,$isrc,0,0,0,0,$w,$h,$size[0],$size[1]);
imagejpeg($idst,'../pics'.$w.'/'.$ffname,90);
imagedestroy($idst);
}
if ($size[0]>360) {
$w=286;
$h=(int)$w*$size[1]/$size[0];
$idst=imagecreatetruecolor($w,$h);
imagecopyresampled($idst,$isrc,0,0,0,0,$w,$h,$size[0],$size[1]);
imagejpeg($idst,'../pics'.$w.'/'.$ffname,90);
imagedestroy($idst);
}
if ($size[0]>630) {
$w=583;
$h=(int)$w*$size[1]/$size[0];
$idst=imagecreatetruecolor($w,$h);
imagecopyresampled($idst,$isrc,0,0,0,0,$w,$h,$size[0],$size[1]);
imagejpeg($idst,'../pics'.$w.'/'.$ffname,90);
imagedestroy($idst);
imagedestroy($isrc);
}
}
header('location:loadpicture.php');
...
?>