Hi jbd7,
Really just to keep you in the loop as whatever I come up with may prove useful to you, I haven’t had a huge amount of time to play with this further but have had another go today, the test function is below:
function responsify_flickr($content) {
$content = preg_replace('/<img(.*title=\"(.*)\")(.*src=\"(.*staticflickr\.com.*)(_.*)\.jpg\")(.*alt=\"(.*)\")(.*)height=\"(\d+)\"(.*)width=\"(\d+)\"(.*)>/i', '<img src="$4_o.jpg" srcset="$4_n.jpg 320w, $4.jpg 500w, $4_z.jpg 640w, $4_c.jpg 800w, $4_b.jpg 1024w, $4_h.jpg 1600w, $4_k.jpg 2048w" title="$2" alt="$7" width="100%" height="$9"/>', $content , -1);
return $content;
}
add_filter( 'the_content', 'responsify_flickr' );
I used the function above which covers all the main resolution categories from Flickr sometimes with multiple values. This wont work as the base filenames change for some of the resolutions. On one example I have been looking at they seem consistent between 320 and 1024 but the original filename and larger sizes have different bases. This means that depending on which image size you selected when adding the image will determine whether the function will work at all. If you picked the original image size (denoted with “_o” in flickr) then it will fail. Same if you had picked one above 1024 wide.
I think the way to solve this so that it works in all situations is to change the insertImage function in the wp-flickr-embed.js file of the plugin to get a list of image names for each size and add the srcset attribute there.
I think it should be possible to get the url data when the callbackPhotoSizes method is called and either build up the srcset tag whilst it is processing the list and store it or store the returned list and build it up in the insertImage function.
Unfortunately I don’t have time to try this now or a suitable WordPress development environment to test it as I wouldn’t want to do that on the live site so it will have to wait until I next get some free time to play with this.
I’ll also post this on the github page in case anyone takes an interest.
Morpheus