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

      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

            Cockney,

            thanks, not quite right, but many thanks anyway... still looking for a way to turn a font into bold... anyone?

            ucbones

              17 years later

              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.

                7 months later

                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.

                  Write a Reply...