Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get custom image sizes added with add_image_size() #6499

Closed
mrleemon opened this issue Apr 30, 2018 · 11 comments
Closed

How to get custom image sizes added with add_image_size() #6499

mrleemon opened this issue Apr 30, 2018 · 11 comments
Labels
[Type] Help Request Help with setup, implementation, or "How do I?" questions.

Comments

@mrleemon
Copy link
Contributor

Issue Overview

Fiddling with the gallery block code I managed to get the thumbnail size of images in addition to their full size using the following code:

onSelectImages( images ) {
    this.props.setAttributes( {
        images: images.map( ( image ) => ( { ...pick( image, [ 'alt', 'caption', 'id', 'url' ] ), thumbnail: get( image, 'sizes.thumbnail.url' ) } ) )
    } );
}

But checking the input images parameter I see that there are no references to custom sizes added with the add_image_size() function, just the core ones. Is this the expected behavior?

@danielbachhuber danielbachhuber added [Type] Help Request Help with setup, implementation, or "How do I?" questions. [Type] Support labels May 25, 2018
@danielbachhuber
Copy link
Member

Hi @mrleemon,

The custom image sizes will only appear if they've been generated for the image. Regenerate Thumbnails is a plugin that lets you regenerate image sizes from the admin, and wp media regenerate is its WP-CLI equivalent if you have command-line access to the site.

@mrleemon
Copy link
Contributor Author

mrleemon commented May 27, 2018

I remember using the Regenerate Thumbnails plugin to generate the custom size thumbnails and after that still seeing just the core size images. I'll try again, maybe that part of the GB code has changed recently.

@mrleemon
Copy link
Contributor Author

mrleemon commented May 27, 2018

The sizes var in the gallery block just contains the urls for the full, large, medium and thumbnail sizes.
The dropdown size selector in the image block contains the full, large, medium-large, medium, thumbnail sizes and the custom size added with add_image_size().
It seems that you are doing something different to get the sizes in both blocks.

@danielbachhuber
Copy link
Member

The dropdown size selector in the image block contains the full, large, medium-large, medium, thumbnail sizes and the custom size added with add_image_size().

I can confirm this behavior:

image

The sizes var in the gallery block just contains the urls for the full, large, medium and thumbnail sizes.

I'm not sure I follow what you mean by this. Can you clarify?

@mrleemon
Copy link
Contributor Author

mrleemon commented May 29, 2018

The sizes var on the images array in the GALLERY block just contains the full, large, medium and thumbnail sizes, not the medium-large nor the custom sizes added via the add_image_size() function (I already regenerated them using the Regenerate Thumbnails plugin).

@danielbachhuber
Copy link
Member

@mrleemon Ok. Can you take a step back and tell me what you're trying to do, and why you're directly modifying the gallery block?

@chrisvanpatten
Copy link
Member

Perhaps related to #1450?

@mrleemon
Copy link
Contributor Author

mrleemon commented May 31, 2018

Right now, with the old [gallery] shortcode one can do something like this easily:

square-thumbnails

But not with the new gallery block because one cannot select the source image size.
I'd like to be able to select the source image size via a dropdown like the image block or via directly modifying the code of the gallery block.

@danielbachhuber
Copy link
Member

Right now, with the old [gallery] shortcode one can do something like this easily:
But not with the new gallery block because one cannot select the source image size.

Makes sense, thanks for clarifying.

I'd like to be able to select the source image size via a dropdown like the image block or via directly modifying the code of the gallery block.

Directly modifying the gallery block code is strongly discouraged. Being able to select the image size is tracked with #1450

@Shanery
Copy link

Shanery commented Apr 3, 2019

I know that it seemed to work in the past but now custom image sizes are not working.

image

image

@tedsecretsource
Copy link

@Shanery I got the custom image sizes to appear in the admin by adding:

add_action( 'admin_init', function() {
	$custom_sizes['my-custom-sizes'] = 'My Custom Size';
	add_filter(
		'image_size_names_choose',
		function( $sizes ) use ( $custom_sizes ) {
			return array_merge( $sizes, $custom_sizes );
		}
	);
});

Remember that they will only show up for images that have been upload after the new image sizes have been defined (IIRC - HTH).

@danielbachhuber Any idea why the custom image sizes aren't showing up in wp-cli? I'm only seeing the default sizes, e.g.: thumbnail, medium, medium_large, large, and full.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Help Request Help with setup, implementation, or "How do I?" questions.
Projects
None yet
Development

No branches or pull requests

5 participants