Osiris: Transparenz bei GIF-Bildern mit PHP („<img src="data: …“)

Beitrag lesen

function _email($address, $type = 'text', $link = 0, $bgcolor = array(255,255,255)){

$pos_at = strpos($address, '@');
  $substr1 = substr($address, 0, $pos_at);
  $substr2 = substr($address, $pos_at + 1);
  $pos_dot = strrpos($substr2, '.');
  $substr3 = substr($substr2, 0, $pos_dot);
  $substr4 = substr($substr2, $pos_dot + 1);
  $address_difficult = $substr1 . ' [an] ' . $substr3 . ' [.] ' . $substr4; // wird für alternativ-Text verwendet (für IE etc., die kein data: unterstützen)

switch($type){
    case 'text':
      return ($link == 0) ? $address : '<a href="mailto:'.$address.'">'.$address.'</a>';
    case 'graphic':
      $textsize = imagettfbbox(10, 0, 'fonts/calibri.ttf', $address);
      $width = $textsize[2] - $textsize[0];
      $height = $textsize[1] - $textsize[7];
      $im = imagecreatetruecolor($width + 5, $height);
      $background_color = ImageColorAllocate ($im, 255, 0, 255);
      ImageFill($im, 0, 0, $background_color);

/und hier kommt der clue:/
imagecolortransparent($im, $background_color);

$black = ImageColorAllocate ($im, 0, 0, 0);
      imagettftext($im, 10, 0, 0, $height - 3, $black, 'calibri.ttf', $address);
      $tmpfname = tempnam ("/tmp", "FOO");
      Imagegif($im,$tmpfname); the file
      $temp = fopen($tmpfname,"rb");for reading binary
      $buffer = fread($temp,filesize($tmpfname));
      fclose($temp);the file
      unlink($tmpfname); with the file, discard
      $out = base64_encode($buffer); // encodieren
      return '<img src="data:image/gif;base64,'.chunk_split($out).'" alt="'.$address_difficult.'" />';
  }
}

  
So, statt ebenfalls nur zu kritisieren, sollst du von mir mal ausnahmsweise eine Lösung bekommen. Denke bitte trotzdem über Martins Vorschläge nach.  
  
Das hier hilft dir vielleicht ebenfalls weiter: http://de.php.net/manual/en/function.imagecolortransparent.php  
  
mfg,  
Marc