mindkomm / timmy

Advanced image handling for Timber.
MIT License
171 stars 13 forks source link

Media Library Thumbnail Size not working #41

Closed dannystarkDE closed 3 years ago

dannystarkDE commented 3 years ago

Hello!

I have a question about the image size in the Media Library. Is it possible that the plugin also affects the thumbnail size in the backend? Currently, images are no longer reduced and always included in full size.

What could be the reason for this?

screenshot_ 2021-06-15_11-55-39

My config:

add_filter("timmy/sizes", function ($sizes) {
    return array(
        "thumbnail" => array(
            "resize" => array(150, 150),
            "srcset" => array(
                25,
                15,
                10,
            ),
            "name" => "Thumbnail",
            "post_types" => array("all"),
        ),
        "medium" => array(
            "resize" => array(240, 240),
            "name" => "Medium",
            "post_types" => array("all"),
        ),
        "medium_large" => array(
            "resize" => array(768),
            "name" => "Medium Large",
            "post_types" => array("all"),
        ),
        "large" => array(
            "resize" => array(1920, 1080),
            "name" => "Large",
            "post_types" => array("all"),
        ),
        "landscape" => array(
            "resize" => array(32, 20, "center"),
            "name" => "Landscape",
            "srcset" => array(
                80,
                60,
                45,
                35,
                25,
                15,
                10,
            ),
            "post_types" => array("all"),
        ),
        "panorama" => array(
            "resize" => array(32, 12),
            "name" => "Panorama",
            "srcset" => array(
                80,
                60,
                45,
                35,
                25,
                15,
                10,
            ),
            "post_types" => array("all"),
        ),
        "portrait" => array(
            "resize" => array(28, 36, "bottom"),
            "name" => "Portrait",
            "srcset" => array(
                80,
                60,
                45,
                35,
                25,
                15,
                10,
            ),
            "post_types" => array("all"),
        ),
        "custom" => array(
            "resize" => array(24, 30, "bottom"),
            "name" => "Portrait",
            "srcset" => array(
                80,
                60,
                45,
                35,
                25,
                15,
                10,
            ),
            "post_types" => array("all"),
        ),
        "square" => array(
            "resize" => array(20, 20, "center"),
            "srcset" => array(
                80,
                60,
                45,
                35,
                25,
                15,
                10,
            ),
            "name" => "Square",
            "post_types" => array("all"),
        ),
        "auto" => array(
            "resize" => array(30),
            "srcset" => array(
                array(2560),
                array(1920),
                array(1400),
                array(1100),
                array(800),
                array(500),
                array(300),
            ),
            "name" => "Auto",
            "post_types" => array("all"),
        ),
    );
});
gchtr commented 3 years ago

Is it possible that the plugin also affects the thumbnail size in the backend? Currently, images are no longer reduced and always included in full size.

Yes, it actually does affect the sizes in the backend. Because Timmy hooks into how images are generated in WordPress core, this also affects the admin. When thumbnails are loaded in the backend, Timmy should load the thumbnail size.

I just checked with the newest version of WordPress and your filter settings. For me, all works as expected.

The HTML that I see in your small developer tools preview looks like you’re looking at the markup for the big preview for an image. Could that be the case?

Compare to this. Here, it’s supposed to load the full size of the image.

In cases like these, it’s also helpful to look at the Network tab in your browser console and filter it by graphics to see what actually gets loaded by the browser:

If the full image size is loaded in your case, I’ll have to look into that more closely.

dannystarkDE commented 3 years ago

Hey. Thanks for your answer. I found my mistake.

It looks like the Timmy Config was too deep down in the functions.php. (At the end of the "function theme_supports()") Now i include the Timmy config in the Timber Constructor and everything worked as expected.

screenshot_ 2021-09-23_21-53-53 screenshot_ 2021-09-23_21-52-30

gchtr commented 3 years ago

Hey @dannystarkDE

Thanks for posting how you solved this issue. I think it’s good to configure Timmy as early as possible, which means not putting it into a special hook.