Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jan 2007
    Location
    Bucharest
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Obfuscate e-mail in a GIF with GD, what to do when text is too large to fit the image

    Hello!

    I'm working at a PHP script that has to obfuscate an e-mail address into a GIF generated with GD.

    I use an Arial font of 10 points (since GD2 takes values in points) and guessing that one average letter is 7.5 pixels this almost does the job. However, if the string I'm trying to obfuscate is composed of many "m"s or "w"s the generated text's width exceeds the image width.

    Is there any way to calculate the width of the image relative to the text?

    Is there any formula between pixels and points?

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,545
    Thanks
    8
    Thanked 1,093 Times in 1,084 Posts
    I sort of have a solution for you.

    Someone else once asked me about getting the pixel width of text.

    So, I thought about using Javascripting to capture the width
    of a <td>. <td>'s will resize to fit any text, so you can measure that
    width in pixels.

    There is a problem though where you need to put that <td> somewhere
    on your page to test it. You could make the text color the same as the
    background so it would be invisible.

    Anyhow, here's the example page: http://www.catpin.com/width.php

    View the HTML source.

  • #3
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you have GD and the Freetype library (look at the output of phpinfo) you can use the imagettfbbox function to return the bounding box size in pixels for the text you are obfuscating.

    imagettfbbox(size, angle, fontfile, text);

    http://www.php.net/manual/en/function.imagettfbbox.php

    Be sure to note the comments about the function returning negative values, and the need to use the abs function (second comment down).

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Use a fixed-width font.

  • #5
    New to the CF scene
    Join Date
    Jan 2007
    Location
    Bucharest
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks AndyR, that did the job!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •