Ecommerce Should be EZ

You can build an e-Biz
We'll show you how!

Logo   Ecommerce Should be Easy

encode and embed images into php

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





Meaulnes Legler

great generator! simple,

great generator! simple, easy to use, exactly what I was looking for: to embed images in my php script.

Best regards

Meaulnes Legler

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <b> <i> <u> <h1> <h2> <h3> <h4> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options