Watermark in Bild

Johnnii360

Erfahrenes Mitglied
Hallo zusammen! :)

Habe auf unserer Opel-Club Homepage für Mitglieder eine Mitgliedergallerie gescriptet.
Damit man beim Bilderklau nicht sagen kann, dass z.B. das Auto von einem Club-Kollegen dem Bilderklauer gehört, habe ich mittels

PHP:
$Hintergrundfarbe = imagecolorallocate($imgB, 255, 255, 255);
$Textfarbe        = imagecolorallocate($imgB, 0, 128, 255);
imagestring ($imgB, 2, 5, 5,  "http://www.opelflashlights.de", $Textfarbe);
eine Url links oben in der Ecke eingefügt. Da dieser aber auf bestimmten Hintergründen nicht gut sichtbar ist oder auch verschwindet, möchte ich gerne ein Bild (png Format mit transparentem Hintergrund) anstelle des Textes einfügen.

Hier mal der komplette Code:

PHP:
// Tumbnail erstellen
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]);
			
		$Hintergrundfarbe = imagecolorallocate($imgB, 255, 255, 255);
		$Textfarbe        = imagecolorallocate($imgB, 0, 128, 255);
		imagestring ($imgB, 2, 5, 5,  "http://www.opelflashlights.de", $Textfarbe);
		
        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]);
		
		$Hintergrundfarbe = imagecolorallocate($imgB, 255, 255, 255);
		$Textfarbe        = imagecolorallocate($imgB, 0, 128, 255);
		imagestring ($imgB, 2, 5, 5,  "http://www.opelflashlights.de", $Textfarbe);
		
        imagepng($imgB, $save);
    } else {
        return FALSE;
    }
}

// Thumbnails erstellen
// Quelldatei
$from = "../../images/memberpics/".$pic[file]."";
// Ziel 1+2
$to = "../../images/memberpics/ofnmp_".$pic[file]."";

// Bildgrösse
$groeße = getimagesize("../../images/memberpics/".$pic[file]."");

// Funktionsaufruf mit Einbehaltung der Proportionen
thumb($from, $to, $groeße[0], $groeße[1], TRUE);

Würde mich sehr auf die Hilfe von euch freuen!
Vielen Dank im Voraus. :)
 
Anstatt dem Codeteil, wo du per [phpf]imagestring[/phpf] deine URL reingesetzt hast...
PHP:
$imgWatermark = imagecreatefrompng("watermark.png");
imagecopy($imgB, $imgWatermark, 5, 5, 0, 0, 60, 60);

Das 5, 5 gibt dabei die Position in $imgB an, an die das Wasserzeichen gesetzt wird. 60, 60 ist die Größe des Wasserzeichenbildes. Entsprechend anpassen und fertig :)
 
Original geschrieben von Matthias Reitinger
Anstatt dem Codeteil, wo du per [phpf]imagestring[/phpf] deine URL reingesetzt hast...
PHP:
$imgWatermark = imagecreatefrompng("watermark.png");
imagecopy($imgB, $imgWatermark, 5, 5, 0, 0, 60, 60);


Das 5, 5 gibt dabei die Position in $imgB an, an die das Wasserzeichen gesetzt wird. 60, 60 ist die Größe des Wasserzeichenbildes. Entsprechend anpassen und fertig :)
Uah, geil! *freu*
Vielen vielen Dank! :)
 
Zurück