EZ eBiz Services
Free eBiz Tools
How-to: Embedding images into your PHP scripts
Sometimes it's useful to distribute a php script that comes complete with a few choice images (such as we did for the Slam Spam project. This allowed us to distribute a single PHP script which people could add to their web site with the images included in the script. No messy distribution of additional files or worry of server load hosting images centrally if your script becomes too popular.
The technique is not complicated but it requires several steps. First, you need to load an image and read it's physical size. Next, compress and base64_encode the image data.
The images are displayed with a call back to the displaying page which has a function that feeds out the correct mime type and image data (uncompressed and un-encoded). Sounds like a headache doesn't it? Well, it's not as bad as writing code generators!
Don't you just love code generation?
I hate Re-writing code and I've written image-embed code several times now! But never again. This little utility will now do all my image encoding and image display code generation.
Try it, it's fun. Just throw in a couple urls to (smallish) images and click submit. The codifubsculator will automatically generate ready-to-paste PHP code with your images embedded!
Feel free to modify the result and don't forget to thank me by spreading the word with a link to this page! ;)
Step 1: provide a list of image URLs