Created
April 27, 2018 13:12
-
-
Save kazimolmez/9c5f8929d875e351d737a547655b6dd1 to your computer and use it in GitHub Desktop.
Php Image Convert Color
This file contains hidden or 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 | |
$myRed = 255; | |
$myGreen = 0; | |
$myBlue = 0; | |
$im = imagecreatefrompng('http://www.clker.com/cliparts/a/5/8/e/1298546227709322759png-transparency-md.png'); | |
imageAlphaBlending($im, true); | |
imageSaveAlpha($im, true); | |
if (imageistruecolor($im)) | |
{ | |
$sx = imagesx($im); | |
$sy = imagesy($im); | |
for ($x = 0; $x < $sx; $x++) | |
{ | |
for ($y = 0; $y < $sy; $y++) | |
{ | |
$c = imagecolorat($im, $x, $y); | |
$a = $c & 0xFF000000; | |
$newColor = $a | $myRed << 16 | $myGreen << 8 | $myBlue; | |
imagesetpixel($im, $x, $y, $newColor ); | |
} | |
} | |
} else { | |
$numColors = imagecolorstotal($im); | |
$transparent = imagecolortransparent($im); | |
for ($i=0; $i < $numColors; $i++) | |
{ | |
if ($i != $transparent) | |
imagecolorset($im, $i, $myRed, $myGreen, $myBlue, $myAlpha); | |
} | |
} | |
header('Content-Type: image/png'); | |
imagepng($im); | |
imagedestroy($im); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment