Last active
July 19, 2019 03:52
-
-
Save cp6/a4ee3f12029850614530ba4c638e4c04 to your computer and use it in GitHub Desktop.
Create png letter icon with PHP
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 | |
function create_icon($first_letter, $second_letter, $save_as) | |
{ | |
$image = ImageCreate(64, 64) or die ("Error making image");//Make the base image (64 x 64) | |
$background_color = ImageColorAllocate($image, rand(0, 255), rand(0, 255), rand(0, 255));//Base image background color (random) | |
$text_color = ImageColorAllocate($image, 255, 255, 255);//White text for font | |
$font = '/var/www/html/ariel.ttf';//Defined font file | |
if ($second_letter == ''){//Positioning for one vs two letters | |
$string = "$first_letter"; | |
$img = imagettftext($image, 36, 0, 17, 47, $text_color, $font, $string); | |
} else { | |
$string = "$first_letter".$second_letter.""; | |
$img = imagettftext($image, 36, 0, 4, 47, $text_color, $font, $string); | |
} | |
$img = Imagepng($image, $save_as);//Finish the image generation | |
imagedestroy($image);//Clear memory? | |
return true; | |
} | |
create_icon('L', 'S', 'icon.png');//Create an icon | |
echo "<img src='icon.png'>";//Show it |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment