Open junaidbhura opened 5 years ago
That would be awesome! Thanks @junaidbhura for all your hard work on the plugin!
Agreed! I've just been starting to experiment with Fly, and my first thought is to filter standard image functions to return fly img tags. Ideally, supporting srcset. This would be great as default functionality.
Thanks!
I've just had a quick play about with Fly after a dev on our team asked about integration with our starter theme. I threw this together, but has no srcset
support.
It hasn't had much testing, just a proof of concept, but seems to work well.
function acme_resize_wp_attachment_image_src($image, $attachment_id, $size, $icon)
{
if (!class_exists('JB\FlyImages\Core') || !method_exists('JB\FlyImages\Core', 'get_instance')) {
return $image;
}
if (is_admin() || $size === 'full') {
return $image;
}
$return = \JB\FlyImages\Core::get_instance()
->get_attachment_image_src($attachment_id, $size, true);
if (empty($return)) {
return $image;
}
return [
$return['src'],
$return['width'],
$return['height'],
true
];
}
add_filter('wp_get_attachment_image_src', 'acme_resize_wp_attachment_image_src', 10, 4);
Example usage:
wp_get_attachment_image($attachment_id, [1500, 350]);
Thanks @crgeary ! Yes that's the direction I was thinking - but there are more hooks for SRCSET and images within post_content. I've already implemented this in https://github.com/junaidbhura/auto-cloudinary/blob/master/inc/class-frontend.php . I just need to port it over!
@junaidbhura thanks for this very useful plugin. I am looking at it with the utlook to use it for a WP Multisite. Before diving into it and do some tests:
I've already implemented this in https://github.com/junaidbhura/auto-cloudinary/blob/master/inc/class-frontend.php . I just need to port it over!
Do you think by porting over that integration the plugin could be already ready to work without using the plugin specific functions? I am dreaming of a activate once and never touch again solution, without customizing the theme code. :)
Kind regards!
Hey @ouun the idea is for it to be possible to work without plugin specific functions, yes!
Thanks @crgeary ! Yes that's the direction I was thinking - but there are more hooks for SRCSET and images within post_content. I've already implemented this in https://github.com/junaidbhura/auto-cloudinary/blob/master/inc/class-frontend.php . I just need to port it over!
This plugin looks perfect! Any idea when you will be able to port over those changes? :)
@aaronjpitts I'd say early next year!
@junaidbhura Looking into integrating this into a project since https://github.com/deliciousbrains/wp-image-processing-queue seems to be unmaintained at this point. Is srcset
support still something you're planning on pursuing with this plugin?
Hi @andrew-boyd although this is part of the roadmap, I'm trying to find time for it - so there's no definitive timeline at the moment. I'm also trying to work out a shared library for dynamic images that can be used across plugins
@joelnewcomer you still haven't got the time 🤷♀️ your code is awesome just needs to have the srcset 👌
Although the initial idea behind this plugin is to be independent of WordPress core functions, it would be good to have the option to make all images dynamic out of the box.
Maybe in version
3.x
🤷♂️