Das PHP Script Verzeichnis

Transparenz auch Durchsichtigkeit genannt bedeutet in Bezug auf Computergrafiken eine Eigenschaft eines Bildelements, durch welche die Inhalte darunter befindlicher Elemente ganz oder auch je nach Definition nur teilweise, zum Beispiel zur Darstellung eines Schattens durchscheinen lassen.

Im Webdesign werden transparente Grafiken sehr oft im Logo- Design eingesetzt, damit der Blog- Header hinter dem Logo zu sehen ist. Die wichtigsten Formate wie php, gif etc. erlauben die Definition transparenter Bildbereiche.

Dieses kleine PHP Script erzeugt eine transparente GIF- Datei.

<?php
// $imageDirectory = the directory of the image with out the trailing slash
// $thumbDirectory = the directory where you want to save the thumb
// $imageName = the file name of the image example: myimage.gif
// $thumbWidth = the final size of the thumb
// $percent = the scaling size of the image. values = .1 - 1

// This function will Save the image on your server
function transparentGif($imageDirectory,$thumbDirectory, $imageName, $thumbWidth){
    $image = imagecreatefromgif("$imageDirectory/$imageName");
    $details = getimagesize("$imageDirectory/$imageName");
    $thumbHeight = $details[1] * ($thumbWidth / $details[0]);
    $resized = imagecreatetruecolor($thumbWidth, $thumbHeight);
    $colorTransparent = imagecolortransparent($image);
    imagepalettecopy($image, $resized);
    imagefill($resized, 0, 0, $colorTransparent);
    imagecolortransparent($resized, $colorTransparent);
    imagecopyresized($resized, $image, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $details[0], $details[1]);
    imagegif($resized,"$thumbDirectory/$imageName");
}

// This function will only display the transparent gif, and not save it
function transparentGifShow($imageDirectory,$thumbDirectory, $imageName,$percent = 1){
    $image = imagecreatefromgif("$imageDirectory/$imageName");
    $details = getimagesize("$imageDirectory/$imageName");
    $thumbHeight = $details[1] * $percent;
    $thumbWidth = $details[0] * $percent;
    $resized = imagecreatetruecolor($thumbWidth, $thumbHeight);
    $colorTransparent = imagecolortransparent($image);
    imagepalettecopy($image, $resized);
    imagefill($resized, 0, 0, $colorTransparent);
    imagecolortransparent($resized, $colorTransparent);
    imagecopyresized($resized, $image, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $details[0], $details[1]);
    imagegif($resized);
}
?>

Quelle: phpsnips.com