So erstelle ich zum Beispiel Thumbnails:
// Methode meiner Klasse
function createThumb() {
$bildData = getimagesize($this->bild);
$ret = false;
$image = null;
$orig = null;
// Orginal laden
switch($bildData[2]) {
case _GIF: $orig = imagecreatefromgif($this->bild);
break;
case _JPEG: $orig = imagecreatefromjpeg($this->bild);
break;
case _PNG: $orig = imagecreatefrompng($this->bild);
break;
default: return false;
}
$hoehe = $bildData[1];
$breite = $bildData[0];
if ($breite > $hoehe) { // Querformat
$xSize = TG_MAX_X;
$ySize = intval($hoehe * $xSize / $breite);
}
else { // Hochformat
$ySize = TG_MAX_X;
$xSize = intval($breite * $ySize / $hoehe);
}
// Resize done
$image = imagecreatetruecolor($xSize, $ySize);
$imageCreated = imagecopyresampled($image, $orig, 0, 0, 0, 0, $xSize, $ySize, $bildData[0], $bildData[1]);
if ($orig !== null) imagedestroy($orig);
// Thumbnail speichern
if ($image !== null && $image != "") {
$name = basename($this->bild);
$pos = strrpos($name, ".");
$name = substr($name, 0, $pos);
$this->thumb = $this->thumbDir."/".$name;
if (imagetypes() & IMG_JPEG) {
$this->thumb .= ".jpg";
$ret = imagejpeg($image, $this->thumb);
}
else if (imagetypes() & IMG_PNG) {
$this->thumb .= ".png";
$ret = imagepng($image, $this->thumb);
}
else if (imagetypes() & IMG_PNG) {
$this->thumb .= ".gif";
$ret = imagejpeg($image, $this->thumb);
}
if ($image != null) imagedestroy($image);
}
return $ret;
}
[/PHP]