Last active
July 21, 2018 15:30
-
-
Save xyulex/aab2e131815c3f260b12 to your computer and use it in GitHub Desktop.
PHP: Add text to transparent PNG image
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 | |
$originalImage = "group_icon.png"; | |
if(file_exists($originalImage)) { | |
$im = imagecreatefrompng($originalImage); | |
imagesavealpha($im, true); // important to keep the png's transparency | |
if(!$im) { | |
die("im is null"); | |
} | |
$black = imagecolorallocate($im, 0, 0, 0); | |
$width = 36; // the width of the image | |
$height = 36; // the height of the image | |
$font = 2; // font size | |
$digit = $i; // digit | |
$leftTextPos = 19 - (strlen($digit)*3); | |
$outputImage = "group_icon_".$digit.".png"; | |
imagestring($im, $font, $leftTextPos, 9, $digit, $black); | |
imagepng($im, $outputImage, 0); | |
imagedestroy($im); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$i; not defined.