Skip to content

Instantly share code, notes, and snippets.

@nikolat
Created February 13, 2011 15:40
Show Gist options
  • Save nikolat/824781 to your computer and use it in GitHub Desktop.
Save nikolat/824781 to your computer and use it in GitHub Desktop.
PNGの左上(x,y)=(0,0)のドットの色全て透過する
<?php
if (!isset($_GET['image_url'])) {
header('HTTP/1.0 400 Bad Request');
header('Content-type: text/plain; charset=utf-8');
exit('Set "image_url" parameter with PNG image URL.');
}
$fileurl = $_GET['image_url'];
$image = @imagecreatefrompng($fileurl);
if (!$image) {
header('HTTP/1.0 500 Internal Server Error');
header('Content-type: text/plain; charset=utf-8');
exit('The image could not loaded.');
}
$x = 0;
$y = 0;
$color_index = imagecolorat($image, $x, $y);
$color_trans = imagecolorsforindex($image, $color_index);
$trans = imagecolorclosest($image, $color_trans['red'], $color_trans['green'], $color_trans['blue']);
imagecolortransparent($image, $trans);
header('Content-type: image/png');
echo imagepng($image);
imagedestroy($image);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment