• Hi all, I’ve been looking throughout the forum and I haven’t seen anything on it.
    I would like to know if there’s a way to convert text to an image. I’ve seen some sites that display an image as their post title and I don’t know how you do that.
    Sorry if this is a stupid question but I have no idea.
    Kind regards to all.

Viewing 15 replies - 16 through 30 (of 34 total)
  • A quick scan of the code matt supplied shows that he’s using the dante.ttf font. So… either you need to get that font, or another and upload it to your site, then change the line
    $font = '/home/photomat/dante.ttf';
    to the font loaded on your site.
    TG

    Got it! Props to Beel for helping this newbie get the hack to work.
    Sweet!
    Thanks again, guys.

    I followed the directions here (user Matt code, call it from a file.php with
    <img src='ttf.php?letters=TEST'>
    And it prints the infinity symbol, and background color but nothing else. Test at https://www.babbler.us/test.php What I am doing wrong? The phpinfo at https://www.babbler.us/phpinfo.php

    You have to have it linked to a proper font, no font = no letters

    I uploaded the fonts. I have arial.ttf and georgia.ttf there right now. It would not print the infinity symbol if the font were not there, right?

    <?php
    $font = '/home/photomat/dante.ttf';
    $letter = urldecode(urldecode($letters));
    $letter = str_replace('_', ' ', $letter);
    $letter = str_replace('.png', '', $letter);
    $im = imagecreate (730, 50);
    $black = imagecolorallocate ($im, 244, 249, 217); // Background
    $white = imagecolorallocate ($im, 69, 78, 63); // Text
    $shadow = imagecolorallocate ($im, 230, 242, 166);
    imagettftext ($im, 32, 0, 23, 34, $shadow, $font, $letter); // Text shadow
    imagettftext ($im, 36, 0, 1, 24, $shadow, $font, '∞'); // Infinity symbol shadow
    imagettftext ($im, 36, 0, 0, 22, imagecolorallocate ($im, 170, 193, 43), $font, '∞'); // Infinity symbol
    imagettftext ($im, 32, 0, 20, 32, $white, $font, $letter); // Text
    header('Content-Type: image/png');
    imagePNG($im);
    imagedestroy ($im);
    ?>

    Where is $black beeing used? The urldecode twice is right? Something is not working right, the infinity symbol prints, the text doesn’t… Weird…

    You need to change:
    $font = ‘/home/photomat/dante.ttf’;
    to point to your font.

    I have. I just copied his original code, since I had questions about it. I have a file named ttf.php:
    <?php
    $font = '/home/babbler.us/babbler/www/ttf/georgia.ttf';
    $letter = urldecode(urldecode($letters));
    $letter = str_replace('_', ' ', $letter);
    $letter = str_replace('.png', '', $letter);
    $im = imagecreate (730, 50);
    $black = imagecolorallocate ($im, 244, 249, 217); // Background
    $white = imagecolorallocate ($im, 69, 78, 63); // Text
    $shadow = imagecolorallocate ($im, 230, 242, 166);
    imagettftext ($im, 32, 0, 23, 34, $shadow, $font, $letter); // Text shadow
    imagettftext ($im, 36, 0, 1, 24, $shadow, $font, '∞'); // Infinity symbol shadow
    imagettftext ($im, 36, 0, 0, 22, imagecolorallocate ($im, 170, 193, 43), $font, '∞'); // Infinity symbol
    imagettftext ($im, 32, 0, 20, 32, $white, $font, $letter); // Text
    header('Content-Type: image/png');
    imagePNG($im);
    imagedestroy ($im);
    ?>

    And yes, gerogia.ttf is there, otherwise the symbol would not print. On the imagettftext lines, if I change $text for some value, like ‘David’, then it will print.
    The test.php file contains:
    <img src=”ttf.php?letters=THIS IS A TEST TO SEE HOW THIS WORKS”>
    I also tried <img src=’ttf.php?letters=THIS IS A TEST TO SEE HOW THIS WORKS’>
    The symbol prints, the text will not.

    I tried to explain how this was done in a sorta step-by-step way when Matt gave me his elf code a while back:
    https://www.seriocomic.com/rhetoric/posts/2004/04/22/the-one-about-making-titles/
    Hope that helps someone…

    Seriocomic, somehow the variable $text is not beeing passed. How or why could that be? Please see https://www.babbler.us/test.php

    Do a test to see if it is an issue with your server. In the code at the top put $letters = “test”; and run the file.

    If I do that Beel, it works. What could be causing that?

    Now try this, put $letters = $_GET[‘letters’]; in place of that line and then try and pass the text.

    It works!! What the heck? Why it wasn’t working before? Please do tell.

    I suspect your version of PHP has register_globals = off

Viewing 15 replies - 16 through 30 (of 34 total)
  • The topic ‘Is there a way to convert images out of text?’ is closed to new replies.