Am very excited at the prospect of generating images on the fly, re-installed PHP (upgraded as well) and grabbed the GD modules.
I have a question though, is there any way to make text bold, or simulate bold text?
Many thanks,
ucbones
Am very excited at the prospect of generating images on the fly, re-installed PHP (upgraded as well) and grabbed the GD modules.
I have a question though, is there any way to make text bold, or simulate bold text?
Many thanks,
ucbones
sorry, here's my code...
$height=30;
$width=130;
header ("Content-type: image/png");
$im = imagecreate ($width, $height);
$black = imagecolorallocate ($im, 0, 0, 0);
$dark = imagecolorallocate ($im, 11, 61, 115);
$light = imagecolorallocate ($im, 145, 168, 249);
$white = imagecolorallocate ($im, 255, 255, 255);
$textbox=imagettfbbox($height-7, 0, "ocraext.ttf", $text);
$textheight=$textbox[1]-$textbox[7];
$textwidth=$textbox[2]-$textbox[0];
$topspace=round(($height-$textheight)/2);
if (($textheight+$topspace-$height) < 0) $start=$height-6;
else $start=$textheight+$topspace;
imagettftext ($im, $height-7, 0, ($width-$textwidth-6), $start, $white, "ocraext.ttf", "$text");
imagepng ($im);
imagedestroy ($im);
many thanks,
ucbones
use a bold font
Cockney,
many thanks for that highly intelligent response. Sadly, I am lacking a bold version of the particular font (OCR A Extended) and have been unable to find one. I was wondering if there was a way to make the fonts bold other than using a bold version of the font. Or, if anyone could talk me through changing my TTF file from normal weight to bold, that would do...
Many thanks,
ucbones
You'll either have to find a bold version of the font , or create one somehow.
I just meant that there's no way of telling imagettftext (); to display text as bold.
Many apologies Cockney,
sadly, I've spent nearly an hour looking for a bold font, all to no avail. Is there an easy way to save a font as itself but bold, if that makes sense?
Many thanks,
ucbones
I've got ocr_ab.ttf which must be very simlar. I'll put it on a server if you want to download.
here you go, if you want to try it
thanks, that would be great
Cockney,
thanks, not quite right, but many thanks anyway... still looking for a way to turn a font into bold... anyone?
ucbones
have a look at mordecai's article here... it's really informing.
http://www.phpbuilder.com/columns/cash20030526.php3
maybe it helps to outline the text in the same color as the text color, you can find on page 3 or somewhere...
tried that, didn't look too good, now trying http://www.phpbuilder.com/board/showthread.php?s=&threadid=10243510
I know this discussion is 17 years old! I just wanted to share a workaround. I was using my own handwriting as a font (created using Windows' FontMaker) which is very faint by default. To make it bold, I simply imagettftext twice, the first time a single pixel to the left and up from the second time.
Hi @calfordmath - what a great thinking-out-the-box method - I tried and it works really well - thanks.
Now, can you think up a way of making it italic. (I'm only joking!) :¬)
redcarpet
I know you're joking but...
It gives slanted text, not proper italics (but then the above just gives a heavier weight, not a proper bold font), but...
Write the text into a temporary image, apply a shear transform (imageaffine, maybe using imageaffinematrixget to build the transformation matrix) that slides the top of the image to the right, and copy the result into the destination image.