Lånt resize script
Hej Alle!Jeg har lånt dette script:
<?
function imageresize($sourcefile,$maxwidth,$maxheight,$destinationfile=false)
{
$types=Array();
$types[1]='gif';
$types[2]='jpeg';
$types[3]='png';
$types[6]='wbmp';
$mimes=Array();
$mimes['gif']='image/gif';
$mimes['jpeg']='image/jpeg';
$mimes['png']='image/png';
$mimes['wbmp']='image/bmp';
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);
}
elseif(function_exists('imagecopyresized'))
{
imagecopyresized($img_dst, $img_src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}
else
{
imagedestroy($img_src);
imagedestroy($img_dst);
return false;
}
if($destinationfile==false)
{
if(isset($mimes[$type]))
{
header('Content-type: '.$mimes[$type_name]);
}
$imagetype($img_dst);
}
else
{
$imagetype($img_dst,$destinationfile);
}
imagedestroy($img_src);
imagedestroy($img_dst);
return true;
}
else
{
return false;
}
}
// Code below is only to demonstrate usage
if(!extension_loaded('gd'))
echo 'Sorry, The GD-extension must be loaded for this to work..';
}
else
{
if(isset($_GET['image']) && $_GET['image'])
{
$file='./logos/'.str_replace(array(' ','/','\\'),'',$_GET['image']);
$width=intval($_GET['width'])>0?intval($_GET['width']):150;
$height=intval($_GET['height'])>0?intval($_GET['height']):150;
if(!imageresize($file,$width,$height))
echo 'Errors opening '.$file.' ... hmm.. :/';
}
else
{
echo '<FORM action="'.$_SERVER['PHP_SELF'].'">'
.'Name: /logos/<SELECT name="image">'
.'<OPTION value="php-med-trans.png">php-med-trans.png</OPTION>'
.'<OPTION value="php-power-black.gif">php-power-black.gif</OPTION>'
.'<OPTION value="php-power-black.png">php-power-black.png</OPTION>'
.'<OPTION value="php-power-white.gif">php-power-white.gif</OPTION>'
.'<OPTION value="php-power-white.png">php-power-white.png</OPTION>'
.'</SELECT><BR>'
.'Max width <INPUT type="text" name="width" value="150"><BR>'
.'Max height <INPUT type="text" name="height" value="150"><BR>'
.'<INPUT type="submit" value="Test!">'
.'</FORM><HR>';
show_source('./'.$_SERVER['PHP_SELF']);
}
}
?>
Men problemet er at der er fejl:
Parse error: parse error, unexpected T_ELSE in /usr/home/web/web36045/adm/inc/upload/upload2.php on line 89
Hvad er forkert der??
Mvh Rasmus
