yabb: Fotos beim Upload automatisch zuschneiden

Beitrag lesen

nicht von mir : aber müsst helfen. Brauchst halt die GDLib auf deinem Server.

Script - thumbnail_20.php

<?php
function thumb($file, $save, $width, $height, $prop = TRUE) {
    // Requires GD-Lib > 2.0
    // Ist $prop=TRUE, so werden die Proportionen des Bildes
    // auch im Thumbnail eingehalten

@unlink($save);
    $infos = @getimagesize($file);
    if($prop) {
        // Proportionen erhalten
        $iWidth = $infos[0];
        $iHeight = $infos[1];
        $iRatioW = $width / $iWidth;
        $iRatioH = $height / $iHeight;
        if ($iRatioW < $iRatioH)
        {
        $iNewW = $iWidth * $iRatioW;
        $iNewH = $iHeight * $iRatioW;
        } else {
        $iNewW = $iWidth * $iRatioH;
        $iNewH = $iHeight * $iRatioH;
        } // end if
    } else {
        // Strecken und Stauchen auf Größe
        $iNewW = $width;
        $iNewH = $height;
    }

if($infos[2] == 2) {
        // Bild ist vom Typ jpg
        $imgA = imagecreatefromjpeg($file);
        $imgB = imagecreatetruecolor($iNewW,$iNewH);
        imagecopyresampled($imgB, $imgA, 0, 0, 0, 0, $iNewW,
                           $iNewH, $infos[0], $infos[1]);
        imagejpeg($imgB, $save);
    } elseif($infos[2] == 3) {
        // Bild ist vom Typ png
        $imgA = imagecreatefrompng($file);
        $imgB = imagecreatetruecolor($iNewW, $iNewH);
        imagecopyresampled($imgB, $imgA, 0, 0, 0, 0, $iNewW,
                           $iNewH, $infos[0], $infos[1]);
        imagepng($imgB, $save);
    } else {
        return FALSE;
    }
}

// Quelldatei
$from = "./meinverzeichnis/an9-6.jpg";
// Ziel 1+2
$to1 = "./th/thumb_a.jpg";
$to2 = "./th/thumb_b.jpg";

// Funktionsaufruf mit Einbehaltung der Proportionen
thumb($from, $to1, 150, 150, TRUE);
// Funktionsaufruf ohne Einbehaltung der Proportionen
thumb($from, $to2, 150, 150, FALSE);
?>

servus