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
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);
?>

Link to comment
Share on other sites

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  :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.