Skip to content

Instantly share code, notes, and snippets.

@khoand0000
Created September 10, 2014 09:24
Show Gist options
  • Save khoand0000/3a112822b13ecee9edf0 to your computer and use it in GitHub Desktop.
Save khoand0000/3a112822b13ecee9edf0 to your computer and use it in GitHub Desktop.
<?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);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment