Wasserzeichen für alle TL / Contao Versionen generieren

Einklappen
X
 
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge
  • Matthias
    Contao-Nutzer
    • 20.06.2009
    • 14

    #1

    Wasserzeichen für alle TL / Contao Versionen generieren

    Hallo Leute,

    da ich Wasserzeichen in einer Galerie (Partybilder eines Clubs) nur bei Vollbild-Anzeigen (Lightbox) integrieren musste und mir keine Erweiterung für Version 2.9.1 bekannt war, möchte ich folgendes nicht vorenthalten:

    Wasserzeichen für hochgeladene Bilder

    Entsprechend dieser Vorgabe habe ich Contao angepasst:

    .htaccess im Hauptverzeichnis
    Code:
    ##
    # watermark
    ##
    RewriteRule ^(.*)tl_files/galerie/(.*) $1watermark.php?src=tl_files/galerie/$2
    watermark.php im Hauptverzeichnis
    PHP-Code:
    <?php
    /**********************************************
    *** Automatic Watermark for Content Images  ***
    ***********************************************
    ***                                         ***
    *** to be used on any CMS.                  ***
    *** do not forget to alter your .htaccess   ***
    *** to rewrite the image paths              ***
    *** to this watermark.php                   ***
    ***                                         ***
    *** Author: Thomas 'Fischi!' Fischer, 2010  ***
    *** based on an idea by webmastersucks.com  ***
    *** http://www.fischi.cc/                   ***
    ***                                         ***
    **********************************************/
    
    // set the header to jpg output, and get the url of the image wth the src parameter.
    header('Content-type: image/jpeg');
    $src = $_GET['src'];
    
    // Check the Imagesize - and insert the right watermark for the right sizes.
    // Here on my blog: Thumbnails are processed with a frame and shadow,
    // small images with a watermark where just my logo is shown
    // and big images with the logo and url. other small images are left untouched.
    $origsize = getimagesize($src);
    
    // set the right watermarks
    if (eregi("270x170", $src)) {
     $watermark = imagecreatefrompng('http://meineseite.de/url.png');
    } else if ($origsize[0] < 280 && $origsize[1] < 280) {
     $skip = "true";
    } else {
     $watermark = imagecreatefrompng('http://meineseite.de/watermark.png');
    }
    
    // create the temporary image. alter the if parameters,
    // if you don't want to process some images, for example transparent png's.
    // of course, there should not be too much trouble with content images.
    if(eregi('.gif',$src)) {
        $image = imagecreatefromgif($src);
    } elseif(eregi('.jpeg',$src)||eregi('.jpg',$src)) {
        $image = imagecreatefromjpeg($src);
    } elseif(eregi('.png',$src)) {
        $image = imagecreatefrompng($src);
    } else {
        exit("Your image is not a gif, jpeg or png image. Sorry.");
    }
    
    // just process the image, if a watermark has to be integrated.
    if ($skip != "true") {
    
        // watermark sizes. strongly recommended to be computed, not set statically.
        $watermark_width = imagesx($watermark);
        $watermark_height = imagesy($watermark);
    
        // get the position of the watermark. calculated from the size of the original image,
        // minus the size of the watermark. feel free to adjust these parameters.
        // for example, if you want the watermark to be displayed on the top left,
        // just set them both to zero. the last parameter (-0) gives you the option of leaving
        // a space between the end of the image and the watermark (kind of the margin in css)
        $dest_x = $origsize[0] - $watermark_width - 0;
        $dest_y = $origsize[1] - $watermark_height - 0;
    
        // putting the watermark on the original image
        imagecolortransparent($watermark, imagecolorat($watermark,0,0));
        imagecopyresampled($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, $watermark_width, $watermark_height);
    
    }
    
    // direct output of the image, as jpg. adjust the last parameter to set the quality.
    imagejpeg($image, "", 100);
    
    // cleaning out the temporary files.
    imagedestroy($image);
    imagedestroy($watermark);
    
    ?>
    Fehlen nur noch die watermark.png bzw. url.png - ebenfalls im Hauptverzeichnis. Läuft.

    Grüße,
    Matthias
    PHP-Code:
    while(!asleep()) sheep++; 
    
  • BugBuster
    Wandelndes Contao-Lexikon
    • 15.06.2009
    • 10679

    #2
    Läuft aber nicht mehr lange:
    • eregi: ist seit PHP 5.3.0 DEPRECATED (veraltet). Sich auf diese Funktion zu verlassen ist in keiner Weise empfehlenswert.

    PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.


    Und über die Endung gehen, obwohl doch über "getimagesize" schon der Bild Typ feststeht, ist eigendlich auch überflüssig.
    In $origsize[2] steht der Typ als Zahl:
    Code:
    1 = GIF, 2 = JPG, 3 = PNG
    4 = SWF, 13 = SWC (zip-like swf file)
    5 = PSD, 6 = BMP, 7 = TIFF(intel byte order), 8 = TIFF(motorola byte order)
    9 = JPC, 10 = JP2, 11 = JPX, 12 = JB2, 13 = SWC, 14 = IFF
    Das mit einer switch-case Anweisung würde dann gleich lesbarer aussehen.
    Zuletzt geändert von BugBuster; 23.09.2010, 01:00.
    Grüße, BugBuster
    "view source" is your guide.
    Danke an alle Amazon Wunschlisten Erfüller

    Kommentar

    • bcit6k
      Contao-Fan
      • 01.02.2010
      • 296

      #3
      hallo,

      danek das du dafür ein modul erstellt hast. aber würde das nicht mit
      phpThumb() is the PHP thumbnail generator. Many image processing options (blur, sharpen, colorize, saturation, gamma, etc) and support for many input image formats across all versions of GD, including JPEG, PNG, GIF and BMP (even without ImageMagick).


      einfacher funktionieren? und vor allem is da auch ein caching dabei!

      Beispiel #7 triffts ganz gut!

      Kommentar

      Lädt...