Andre
Andre

Reputation: 77

WordPress grayscale specific image size

What to do: add a new image size and grayscale this specific size.

What I've done so far: I've been searching around and found this helpfull URLs: wpbeginner, Ryan Berry. The second solution creates a grayscale image for each size on every new image and is nearly what I'm searching for.

The Problem: I know how to add a new image size and the above functions creating grayscale images. What I don't know is how to add this filter just to a specific size.

Upvotes: 0

Views: 347

Answers (1)

deathlock
deathlock

Reputation: 2837

Using the code from wpbeginner, it seems it only grayscales image which is specified as themename-bw-image, as seen from here (line 04):

$file = trailingslashit($file['path']).$meta['sizes']['themename-bw-image']['file'];

So I suppose if you don't want the image to get grayscaled, you could add a new image size:

add_action('after_setup_theme','themename_bw_size');
function themename_bw_size() {
    add_image_size('themename-bw-image', 100, 100, true);
    add_image_size('other-nongrayscaled-image', 150, 150, true);
    // etc...
}

Upvotes: 1

Related Questions