junaidbhura / fly-dynamic-image-resizer

Fly Dynamic Image Resizer plugin for WordPress
https://wordpress.org/plugins/fly-dynamic-image-resizer/
MIT License
162 stars 26 forks source link

Hook into WordPress core functions #26

Open junaidbhura opened 5 years ago

junaidbhura commented 5 years ago

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 🤷‍♂️

joelnewcomer commented 5 years ago

That would be awesome! Thanks @junaidbhura for all your hard work on the plugin!

g000m commented 5 years ago

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!

crgeary commented 4 years ago

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]);
junaidbhura commented 4 years ago

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!

ouun commented 4 years ago

@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!

junaidbhura commented 4 years ago

Hey @ouun the idea is for it to be possible to work without plugin specific functions, yes!

aaronjpitts commented 3 years ago

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? :)

junaidbhura commented 3 years ago

@aaronjpitts I'd say early next year!

andrew-boyd commented 3 years ago

@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?

junaidbhura commented 3 years ago

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

ibrahimwithi commented 2 years ago

@joelnewcomer you still haven't got the time 🤷‍♀️ your code is awesome just needs to have the srcset 👌