We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Text-to-PNG plugin

Development and Programming

Michiel Papenhove's avatar
Michiel Papenhove
9 posts
16 years ago
Michiel Papenhove's avatar Michiel Papenhove

Hello,

Recently I had to develop a website and the client I made it for, really wanted to have a lot of the content shown using “their” font. They wanted to be able to make new menu items and stuff like that, but have absolutely no idea how to work with a program like Photoshop.

To get this happening, I made a plugin called Renderer, which basically does one thing: it takes the text you enter between the plugin tags and renders it to a PNG image, using a TTF file to render the text.

The plugin uses the GD library and the PHP image functions to render the image. Besides that, it also uses a function (file_get_contents in combination with URLs) that is disabled by some hosting companies. So make sure you have both the GD library enabled and that file_get_contents is allowed to perform HTTP calls before even trying the plugin.

An example:

{exp:renderer:render font="arial" size="16" color="000000" bg="ffffff"}
The text you want rendered
{/exp:renderer:render}

This will show up as a PNG image as soon as you visit your site. The text will be rendered using the “color” value with its background transparent and the edges of the font using the bg color. Some sort of simple ‘anti-aliasing’, if you’d like.

As soon as the image has been created, it will be cached. This will obviously enhance the performance of your web server due to the fact that the PNG only needs to be rendered once. This behaviour can be disabled, if desired.

This plugin is definitely not in its final state and I would love any suggestions to progress its development.

You can find the plugin and more information/examples here:

http://ee.dev-hell.com/plugins/renderer

regards, Michiel.

       
Adam George's avatar
Adam George
283 posts
16 years ago
Adam George's avatar Adam George

Hey this sounds great! Well done!

I noticed that in your example image, the tag contains width and height values - is that something the plugin generates or did you add that later?

It would be nice if you could view the image directly, and ‘save image as’ instead of it showing up as a php file, but other than that, awesome!

       
Michiel Papenhove's avatar
Michiel Papenhove
9 posts
16 years ago
Michiel Papenhove's avatar Michiel Papenhove
Hey this sounds great! Well done! I noticed that in your example image, the tag contains width and height values - is that something the plugin generates or did you add that later? It would be nice if you could view the image directly, and ‘save image as’ instead of it showing up as a php file, but other than that, awesome!

Thanks for the kind words 😊 Great that you like it.

The width and height values are added by the plugin, but only if the server you’re hosting the EE site on has support for use file_get_contents with URLs (this is sometimes disabled by hosting companies). The addon will open the image file and determine its width and height. This will not work correctly the first time the image is generated (due to timing, usually only the height works the first time), but that’s not really a big problem.

I don’t know if I get what you mean with your last sentence, but it wouldn’t be that hard to make your browser save the image immediately. At this moment I just pass an image header, but if you also add a content-disposition header, you could make it so that generating the image triggers a “save file as” dialog.

If you have any more questions or suggestions, feel free to let me know about them.

Michiel.

       
Ingmar Greil's avatar
Ingmar Greil
29,243 posts
16 years ago
Ingmar Greil's avatar Ingmar Greil

Just for reference, there is a module (!) out there that essentially seems to be doing the same thing.

       
Michiel Papenhove's avatar
Michiel Papenhove
9 posts
16 years ago
Michiel Papenhove's avatar Michiel Papenhove

Thanks Ingmar,

I had scanned the plugins for something similar but couldn’t find anything… I guess I had to take a look at the modules too 😊 Well, for people who prefer a plugin instead of a module, my addon is probably still usable.

Regards, Michiel.

       
Ingmar Greil's avatar
Ingmar Greil
29,243 posts
16 years ago
Ingmar Greil's avatar Ingmar Greil

Oh, I am sure it is. Just wanted to cross-reference the threads. Personally, I’d consider a plugin the way to go 😊

       
TechWench's avatar
TechWench
30 posts
16 years ago
TechWench's avatar TechWench

I think this is great!

One thing with this plugin (which is similar to my original first-draft module release) is that it exposes the system url. I took a lot of flack for it when I first put my module up, but I did have plans to expand it - I hastily wrote it during the 2nd half of the blogathon and was half-asleep…that’s my excuse and I’m sticking to it. 😉

My first run was exactly like this - where it used query strings on the generator script. But starting it out as a module made it easy for me go in and add more functionality and customizability (is that even a word?).

Anyway, I think this is great. My site is down and the module is unavailable (reinstalling ee), but I’ll put a link on my placeholder page to this thread for an alternative. 😊

       
Chris Newton's avatar
Chris Newton
440 posts
16 years ago
Chris Newton's avatar Chris Newton

I made a small modification to your plugin that replaces file_get_contents with a function that attempts to call cURL first, then file_get_contents if cURL’s not available. This will allow this to be run on sites with more file access restriction (Dreamhost for instance)

       
TonyNibbles's avatar
TonyNibbles
98 posts
16 years ago
TonyNibbles's avatar TonyNibbles

Hey all,

As posted in the other thread, you might want to check out my module - it does the same thing, only uses a different text rendering engine that supports proper anti aliasing and it uses this to output a 24-bit PNG.

http://ellislab.com/forums/viewthread/94514/

       
Nico Smit's avatar
Nico Smit
48 posts
16 years ago
Nico Smit's avatar Nico Smit

Where can I download this plugin? The link above is down.

       
Chris Newton's avatar
Chris Newton
440 posts
16 years ago
Chris Newton's avatar Chris Newton

Since dev-hell seems to be offline, you can just download my slightly modified version in my post above.

       
Nico Smit's avatar
Nico Smit
48 posts
16 years ago
Nico Smit's avatar Nico Smit

Hi Chris,

I did, but you didn’t include plugins/renderer/renderer.php I mean; this file is necessary, right?

       
TonyNibbles's avatar
TonyNibbles
98 posts
16 years ago
TonyNibbles's avatar TonyNibbles

My module is still available, linked above 😊

       
Chris Newton's avatar
Chris Newton
440 posts
16 years ago
Chris Newton's avatar Chris Newton

There’s the full package.

http://barrettnewton.com/dont_delete/title_font_renderer.zip

       
Nico Smit's avatar
Nico Smit
48 posts
16 years ago
Nico Smit's avatar Nico Smit

I’ve tried to use global variables with the plugin, but global variable names with underscores (_) aren’t allowed, so {global_variable} return {global_variable} or {global_variable} to be more specific.

When I remove urlencode() function in the line below, I does work, but is this a long-term solution? Does anybody know a better solution?

thanks

       
1 2

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.