×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Bernd Obermayr
Added: Jun 17, 2019 12:50 PM
Modified: Jun 18, 2019 10:52 AM
Views: 3954
Tags: php
  1. /**
  2.  * Erzeuge einen spacer mit $breite und $höhe wenn filename noch nicht existiert
  3.  * module itlFunctions.php
  4.  * Ergibt ein Bild 100px breit, 10px hoch, Text=spacer, Pfad = pict/
  5.  * @param int $breite
  6.  * @param int $hoehe
  7.  * @param string $txt Text der in die Grafik eingebettet wird
  8.  * @param string $path Pfad relativ zum script, hier also 'pict/'
  9.  *
  10.  * <code>
  11.  * example:<br>
  12.  *  $img    = tmpspacer(100, 10, "spacer", "pict/");<br>
  13.  *  $spacer = "&lt;img class='spacer' border=0 alt='spacer100x10' src='/itl/$img'/&gt;";
  14.  * </code>
  15.  * @return string filename
  16.  * @file itlFunctions.php
  17.  */
  18. function tmpspacer($breite, $hoehe = 1, $txt = NULL, $path = "./") {
  19.     //Bild erzeugen
  20.     $filename = trim("$path${breite}x${hoehe}.png");
  21.     if (!file_exists($filename)) {
  22.         //messagebox(basename(__FILE__) . " M:" . __METHOD__ . " Z:" . __LINE__ . "||H:$hoehe" . "B:$breite", "bottom:5px", "right:10px;height:auto;", "infobox");
  23.         $img = imagecreate((int) $breite, (int) $hoehe);
  24.  
  25.         //
  26.         $color['lime']  = imagecolorallocate($img, 0x00, 0xFF, 0x00);
  27.         //Schwarze Farbe setzen
  28.         $color['black'] = imagecolorallocate($img, 0x00, 0x00, 0x00);
  29.         //Text schreiben
  30.         if ($txt) {
  31.             imagestring($img, 2, 2, 2, $txt, $color['black']);
  32.         }
  33.         //Hintergrundfarbe entfernen (transparent)
  34.         imagecolortransparent($img, $color['lime']);
  35.         //PNG erzeugen
  36.         imagepng($img, $filename, 9);
  37.     }
  38.     return $filename;
  39. }
  40.