Skip to content

Instantly share code, notes, and snippets.

@mgng
Created December 10, 2008 15:04
Show Gist options
  • Save mgng/34342 to your computer and use it in GitHub Desktop.
Save mgng/34342 to your computer and use it in GitHub Desktop.
gif transparent check
<?php
// gif transparent check
function getGifTp($imgPath) {
$sz = getimagesize($imgPath);
$x = $sz[0];
$y = $sz[1];
$im = imagecreatefromgif($imgPath);
for($sx=0; $sx<$x; $sx++) {
for($sy=0; $sy<$y; $sy++) {
$rgb = imagecolorat($im, $sx, $sy);
$idx = imagecolorsforindex($im, $rgb);
if ($idx['alpha'] !== 0) {
imagedestroy($im);
return $idx;
}
}
}
imagedestroy($im);
return false;
}
var_dump(
getGifTp('transparent.gif'), // array
getGifTp('default.gif') // null
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment