fly-dynamic-image-resizer icon indicating copy to clipboard operation
fly-dynamic-image-resizer copied to clipboard

Hook into WordPress core functions

Open junaidbhura opened this issue 6 years ago • 11 comments
trafficstars

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

junaidbhura avatar Jun 11 '19 10:06 junaidbhura

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

joelnewcomer avatar Jun 11 '19 12:06 joelnewcomer

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!

g000m avatar Jun 23 '19 09:06 g000m

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]);

crgeary avatar Aug 25 '20 14:08 crgeary

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 avatar Aug 25 '20 22:08 junaidbhura

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

ouun avatar Aug 30 '20 22:08 ouun

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

junaidbhura avatar Sep 11 '20 07:09 junaidbhura

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 avatar Oct 02 '20 09:10 aaronjpitts

@aaronjpitts I'd say early next year!

junaidbhura avatar Oct 06 '20 23:10 junaidbhura

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

andrew-boyd avatar Mar 23 '21 15:03 andrew-boyd

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

junaidbhura avatar Mar 24 '21 03:03 junaidbhura

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

ibrahimwithi avatar Sep 16 '22 12:09 ibrahimwithi