Code: Alles auswählen
<?PHP
function img_resize($path,$w=0,$h=0,$quality=100,$save='') {
// echo('Breit: '.$image_data[0].' | Hoch: '.$image_data[1].' | Typ: '.$image_data[2].' | Mime: '.$image_data['mime']);
$image_data = @getimagesize($path);
$image_type = $image_data[2];
$gd_ext = array('','jpg','gif');
if ($image_type != 1 && $image_type != 2)
return false;
if ($save == '')
header('Content-type: '.$image_data['mime']);
else
$save = eregi_replace('%ext',$gd_ext[$image_type],$save);
if ($w != 0) {
// echo(' Breite angegeben ');
$rapporto = $image_data[0] / $w;
if ($h != 0) {
// echo(' Höhe angegeben ');
if ($image_data[1] / $rapporto > $h)
$rapporto = $image_data[1] / $h;
}
}
elseif ($h != 0) {
// echo(' NUR Höhe angegeben ');
$tmp_h = $image_data[1] / $h;
}
else {
// echo(' Keine Größen angegeben ');
return false;
}
$thumb_w = $image_data[0] / $rapporto;
$thumb_h = $image_data[1] / $rapporto;
if ($image_type == 1)
$img_src = @imagecreatefromgif($path);
elseif ($image_type == 2)
$img_src = @imagecreatefromjpeg($path);
$img_thumb = @imagecreatetruecolor($thumb_w,$thumb_h);
$result = @imagecopyresampled($img_thumb,$img_src,0,0,0,0,$thumb_w,$thumb_h,$image_data[0],$image_data[1]);
if (!$img_src || !$img_thumb || !$result)
return false;
if ($image_type == 1)
$result = @imagegif($img_thumb,$save);
elseif ($image_type == 2)
$result = @imagejpeg($img_thumb,$save,$quality);
return $result;
}
?>
Diesen habe ich in einer Datei namens resize.php abgespeichert.
Wie kann ich nun aber die Funktion nutzen?
Beim Test in der gleichen Datei Thumbs auszugeben mit
Code: Alles auswählen
img_resize('fsv_rassnitz.gif',30,30,100,'')
In andere Datei mit include und echo gehts scheinbar gar nicht.
Das Speichern will so oder so nicht funktionieren.