I have a plugin that generates a gallery of user photos. Currently, it works using img
tags pointing to the user photo image. It attaches to the the_content
filter.
I'm experimenting with converting to using data URLs. I'm able to generate them with no difficulty, but when I change the code to insert them into the page, requests to that page come back with zero content (i.e. zero length). However, I still get a 200 status code and I don't see any errors in my logs.
So, I'm wondering if WP has a limit on the size of page it will send. The data URLs add up to around 1MB, so I was wondering if that tripped it over some limit.
Any suggestions?
The salient code is:
$file = trailingslashit($upload_dir['basedir']) . 'userphoto/' . $image_file;
$fileContents = base64_encode(file_get_contents($file));
error_log($fileContents);
$src = "data:image/jpg;base64,$fileContents";
...
...
$img .= '<img src="' . htmlspecialchars($src) . '"';
...
$img .= ' />';
In case it's relevant, the content is in a page not a post and it would go here: http://nerdnite.com/nerds/
So, that page, but with data URLs instead of image source files.
EDIT
What I do now know is that it's not the generation of the content string by the filter. I can generate the string (which is of length 1229923), but if I pass a dummy string back, everything works well.
My memory usage is negligible and I'm nowhere near my PHP limit... so it seems to be something to do with WordPress trying to handle that huge string.
img
element. If I set thesrc
attribute to the URL of the image, it works without any problems. If I switch to set thesrc
to a data URL, I get a zero-length response. The only difference between the two is the code above.