Created
February 13, 2011 15:40
-
-
Save nikolat/824781 to your computer and use it in GitHub Desktop.
PNGの左上(x,y)=(0,0)のドットの色全て透過する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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