Created
July 19, 2013 21:49
-
-
Save tcelestino/6042604 to your computer and use it in GitHub Desktop.
Generator image with text in 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 | |
// Defini o caminho da imagem sabe | |
$img = card.jpg; | |
// Cria um jpg com base na imagem base, essa será a nova imagem | |
$i = imagecreatefromjpeg($img); | |
// Definições do texto | |
$texto = "Aqui o texto que será escrito na imagem"; | |
$cor = imagecolorallocate($i, 133, 73, 72); // cor da fonte | |
$fonte = "MarketingScript.ttf"; // fonte que será utilizada | |
$tamanho_fonte = 16; // tamanho da fonte | |
$nome_arquivo_novo = "imagens/" . md5(date("Y-m-d H:i")) . ".jpg"; // onde o novo arquivo será salvo, usei md5() pra gerar o nome da imagem | |
// Escreve o texto na imagem, com base nas definições acima | |
// 230 e 450 é a posição em que o texto será gravado na imagem | |
imagettftext($i, $tamanho_fonte, 0, 230, 450, $cor, $fonte, $texto); | |
// Gera a imagem, 75 é a qualidade, 100 é o maximo | |
imagejpeg($i, $nome_arquivo_novo, 75); | |
// Destroi a imagem para liberar memória | |
imagedestroy($i); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment