PHP to Generate Text/Images on the fly

Discussion in 'PHP' started by LazyD, May 10, 2007.

  1. #1
    So, ive had this curious idea flying through my head...

    I would like to make the section headers on my site in the cool font I used on the rest of my site, but I dont feel like creating/saving an image for every article/page of my site.

    So I was thinking, people use fonts to and PHP to create captchas all the time...What would stop me from uploading that font to my server and using GD to create the image on the fly, so for instance, if I had an article called "Canceling a Capitol One Credit Card" it would take that from a variable, pass it to the GD function to create an image with my font that said "Canceling a Capitol One Credit Card" then displayed that image on the screen....

    Possible? Worthwhile?

    It would also be interesting to name it whatever you wanted, then have it save it to a folder, then when someone else accesses the same page, it checks to see if it exists, if it does, bypasses the GD function and displays the existing image, otherwise, generate it...
     
    LazyD, May 10, 2007 IP
  2. cbn81

    cbn81 Peon

    Messages:
    160
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Why not just writing the text using that font?
     
    cbn81, May 10, 2007 IP
  3. LazyD

    LazyD Peon

    Messages:
    425
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The font is a non-standard font....

    I dont want users to come to my site and be forced to download a font or be given errors about not having it

    I also dont want to be in photoshop everyday making up new images for each article that is posted.
     
    LazyD, May 10, 2007 IP
  4. cbn81

    cbn81 Peon

    Messages:
    160
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    cbn81, May 10, 2007 IP
  5. LazyD

    LazyD Peon

    Messages:
    425
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I know it can be done, I was more curious to hear opinions on why you should/shouldnt do this or if anyone had an opinion on the matter...
     
    LazyD, May 10, 2007 IP
  6. lemaitre

    lemaitre Peon

    Messages:
    61
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #6
    It's a perfectly reasonable idea. The cached image should be named after the text it contains so that if the text changes, there will be a cache miss and a new image will be generated with the proper text.
     
    lemaitre, May 10, 2007 IP
  7. LazyD

    LazyD Peon

    Messages:
    425
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Exactly lemaitre...

    The only issue I see in doing this is, unless I repeat the title of the story somewhere in proper HTML, I wont get the benefit of having the title in H1 tags. Its not really an issue because with a little creative CSS I can put the title just about anywhere and format it to look normal...
     
    LazyD, May 10, 2007 IP
  8. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #8
    It's certainly possible and relatively simple but I'm not sure I would bother. Sure it may make you site look a little bit better to you but just because you like the font doesn't mean everyone else does. If they want to override the default font settings to something easier to read or make the size smaller or larger, they'll be stuck with your title image. I'm not a big fan of using images unless absolutely needed - if it can be done in text, do it. Also if you have anyone browsing on a mobile device, I'm sure they would much rather not have to download the image.

    But it's up to you. Personally I wouldn't, but I can't think of any major flaws with your idea.
     
    rodney88, May 11, 2007 IP
  9. xooMan

    xooMan Peon

    Messages:
    92
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #9
    It's not that good from the SEO perspective. <h1> or <h2> tags are much better than <img /> as titles, since search engines will rank them higher.
     
    xooMan, May 11, 2007 IP
  10. LazyD

    LazyD Peon

    Messages:
    425
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #10
    xooMan, I understand, that was my point, it seems the only real flaw with this is that you cant put the image in an H1 tag, thats why im thinking that ill sneak the title in somewhere near it and format it with CSS to blend with the rest of the content...
     
    LazyD, May 11, 2007 IP
  11. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #11
    <h1 id="theHeaderTag">Header tag</h1>

    onload="I'd use ajax to swap the text for the dynamically generated image"

    I'd do that ..... the spiders will see text, the users will see the image you want them to see, bypassing seo issues.....
     
    krakjoe, May 11, 2007 IP
  12. LazyD

    LazyD Peon

    Messages:
    425
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #12
    krakjoe - perfect, I guess that also means if someone has javascript disabled it will depracate back to normal HTML

    Ugh, this makes me wish I knew javascript or AJAX, anyone know of a script that will do what im looking for, or point me in the right direction?
     
    LazyD, May 11, 2007 IP
  13. xooMan

    xooMan Peon

    Messages:
    92
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #13
    I've created a sample that demonstrates what you want: replaces titles with images if JavaScript is enabled.

    Please check the attachment.
     

    Attached Files:

    xooMan, May 11, 2007 IP
    LazyD likes this.
  14. LazyD

    LazyD Peon

    Messages:
    425
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #14
    +rep for that awesome code...

    Once I get it all put together I would be happy to post it if anyone was interested...
     
    LazyD, May 12, 2007 IP
  15. xooMan

    xooMan Peon

    Messages:
    92
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #15
    Sure, once you are done please provide a link. It would be great to take a look. And thanks for the rep ;)
     
    xooMan, May 13, 2007 IP
  16. gandaliter

    gandaliter Peon

    Messages:
    64
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #16
    I have to say, I think it would be a slight waste of time. However I am very interested in how you do it, and will investigate image generation. So thanks for bringing it up.
     
    gandaliter, May 13, 2007 IP
  17. wing

    wing Active Member

    Messages:
    210
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    58
    #17
    Neat xooMan, very creative :)
     
    wing, May 13, 2007 IP
  18. LazyD

    LazyD Peon

    Messages:
    425
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #18
    Im still working on this concept, however, im not much of a GD expert...

    Is it possible to apply a background image to the image im making then write the text on top of it?

    If the above is not possible, can I simply make the background of the image transparent and then just the write text to that image so the background shows up behind it on the page?
     
    LazyD, May 20, 2007 IP
  19. xooMan

    xooMan Peon

    Messages:
    92
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #19
    xooMan, May 20, 2007 IP