Jump to content

[SOLVED] Image GD apply font


DeanWhitehouse

Recommended Posts

I have this code

<?php
/*
put ONLY this code into a file called image.php
put a image called "myimage.jpg" info the same folder then 
open image.php
*/
if(isset($_GET['date']))
{
$date = $_GET['date'];
$first =  $_GET['first'];
$last =  $_GET['last'];
$id =  $_GET['id'];
$pfirst =  $_GET['pfirst'];
$plast =  $_GET['plast'];
$imgname = "discount.jpg";
$im = imagecreatefromjpeg($imgname);
$tc  = imagecolorallocate($im, 0, 0, 0);
//imagestring($im, 1, 5, 5, "Details", $tc);
imagestring($im,5,50,100,"Date:".$date,$tc);
header("Content-Type: image/jpeg");
imagejpeg($im);
}
?>

 

and the image is produced fine, but the font style looks horrible, and from what i read on the PHP manual you need to upload a font file to change it , is there a way i can just use a font e.g. ariel?

Link to comment
https://forums.phpfreaks.com/topic/119499-solved-image-gd-apply-font/
Share on other sites

this code doesnt work i get an error message saying there is an error.

 

<?php
// Set the content-type
header("Content-type: image/png");

// Create the image
$im = imagecreatefromjpeg($imgname);
$tc  = imagecolorallocate($im, 0, 0, 0);

// The text to draw
$text = 'Testing...';
// Replace path by your own font path
$font = 'arial.ttf';

// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);

// Add the text
imagettftext($im, 20, 0, 10, 20, $tc, $font, $text);

// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>

update on the code

<?php
// Set the content-type
header("Content-type: image/png");

// Create the image
$imgname = "discount.jpg";
$im = imagecreatefromjpeg($imgname);
$tc  = imagecolorallocate($im, 0, 0, 0);

// The text to draw
$text = 'Testing...';
// Replace path by your own font path
$font = 'arial.ttf';

// Add the text
imagettftext($im, 20, 0, 10, 20, $tc, $font, $text);

// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>

 

still getting error though :(

 

Solved now ,it was the shadow bit  :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.