Simply put, the following HTML code should show a picture of a string "ABC18"
<image src="http://mydrupalsite.com/mymodule/string-to-image/ABC18">

I am new to drupal and have no idea how to generate an image on the fly and return it. I think I need a hook mymodule_menu with REST path 'mymodule/string-to-image' pointing to my function... But how should I handle this custom string? And how should I generate an image on the fly and return it with a proper content type from Drupal?

Any advice will be deeply appreciated.

-Nick

Comments

dman’s picture

You'll have to start with the appropriate php documentation about making images on the fly.

Create a bunch of non-drupal php examples until you get what you want.

Then, once you've figured that out, the only drupal-ness will be making sure the right headers are sent.

For the rest of it, you've got the right idea about implimenting your own module URL and using the argument as the string to return.

It's not a small task you are trying to do here, if you are really starting from scratch. You will probably be able to find other script examples on the web of dynamic php-image-button/banner creators.
Remember to build in caching to your solution - it'll make a big difference.

.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/

Steven’s picture

The only Drupal-specific thing you need to do is use drupal_header() instead of header() so that headers can be cached, really. Of course, you could use the image API as well, though it is not suitable for advanced graphics operations (like what color.module does for example).

--
If you have a problem, please search before posting a question.

nmakarov’s picture

Thanks, Steven.

drupal_set_header - that's what I needed. I didn't realize it is that simple - just a normal use of GD functions. I thought Drupal should have its own image processing toolkit, found some functions like image_gd_xxx and was trying to use them... but there is no ImageCreate function there...

So your answer was really helpfull and I appreciate that.

-Nick