Got to get back here.
This code works fine to auto-convert image to base64
- Code: Select all
<img src="data:image/png;base64,<cms:php>echo base64_encode(file_get_contents(ltrim(parse_url('<cms:show logo />', PHP_URL_PATH), '/')));</cms:php>"/>
First, we get a full URL of the logo image by cms:show logo
Then, I use parse_url
function from php. I make it extract only path without domain.
Then we need to remove a slash on the left with the php function ltrim
After such mod everything else works great. Even large images can be converted on the fly.
I checked with over 1mb of images and total like 10 images at page load. Didn't notice slow downs. Worked pretty fast. But I'm only using it for a bunch of small pics, like icons and logo. Saved requests and 503 errors with cheap hosting.