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

Custom Image sizes are not listed for Gallery Block. #13434

Closed
prajaktagadhave123 opened this issue Jan 23, 2019 · 17 comments
Closed

Custom Image sizes are not listed for Gallery Block. #13434

prajaktagadhave123 opened this issue Jan 23, 2019 · 17 comments
Labels
[Block] Gallery Affects the Gallery Block - used to display groups of images [Block] Image Affects the Image Block Needs Technical Feedback Needs testing from a developer perspective.

Comments

@prajaktagadhave123
Copy link

Describe the bug
Custom Image sizes are not listed for Gallery Block.

To Reproduce
Steps to reproduce the behavior:

  1. Go to Page- Add gallery block. Add custom image sizes using add_image_size in your themes function.php.
  2. Click on image block. See image size options. this listed only full, medium and thumbnail.

Expected behavior
It should list all image sizes including custom image sizes.

Screenshots
Image Size - http://screenshots.sharkz.in/prajakta/2019/01/2019-01-23_12-45-39.png
Default image sizes - http://screenshots.sharkz.in/prajakta/2019/01/2019-01-23_12-46-12.png

Additional context
I just tried Image block. I could not find all image sizes under image size option. I have added added custom image sizes. Only default full size, thumbnail, medium sizes listed only.

I tried using regenerate thumbnail plugin.

Is there any issue while retriving image sizes?

@swissspidy swissspidy added Needs Technical Feedback Needs testing from a developer perspective. [Block] Gallery Affects the Gallery Block - used to display groups of images [Block] Image Affects the Image Block labels Jan 24, 2019
@swissspidy
Copy link
Member

Image sizes are only shown if an image with that size actually exists. Just adding a bunch of add_image_size doesn't change anything. You might need to upload a new image to see the effect or regenerate thumbnails for existing images.

@matiyin
Copy link

matiyin commented Feb 7, 2019

Image sizes are only shown if an image with that size actually exists. Just adding a bunch of add_image_size doesn't change anything. You might need to upload a new image to see the effect or regenerate thumbnails for existing images.

It's simply not true what you're saying. Prajakta is right and the core Image block doesn't not allow you to select a custom size set with add_image_size out of the box.

If it should, then please point us in the right direction.

@NRDay
Copy link

NRDay commented Apr 7, 2019

For custom image sizes to be available in the admin you need to filter 'image_size_name_choose'.

See here

Example:

add_filter( 'image_size_names_choose', 'my_custom_sizes' );
 
function my_custom_sizes( $sizes ) {
    return array_merge( $sizes, array(
        'gallery-thumb' => __( 'Gallery Thumb' ),
        'medium-square' => __( 'Medium Square' )
    ) );
}

@ghost
Copy link

ghost commented Apr 10, 2019

@NRDay This shouldn't be necessary.

I would expect all image sizes, including custom image sizes to be showing up in this dropdown list.

This should be considered by default.

@NRDay
Copy link

NRDay commented Apr 10, 2019

@leecollings I guess the thinking is that some plugins create their own thumbnails that are not meant for use within general content and this filters gives developers the option to expose them or not.

Either way, using the filter solves the issue.

@ghost
Copy link

ghost commented Apr 10, 2019

@NRDay Hmm I see your point actually, yes I agree.

@CameronVerto
Copy link

@NRDay Would one not assume that such scenarios are the exception rather than the rule? I would expect developers should need to explicitly hide them rather than explicitly show them. All of us needed to explicitly add the image sizes and found ourselves on this issue, thinking their seemingly inexplicable absence was a bug. However, if they were showing in the list in the first instance, we would be looking for a means to hide them, knowing exactly what we want rather than thinking it is broken. In other words, I imagine most people will expect their image size to be available once it is added.

@NRDay
Copy link

NRDay commented Apr 17, 2019

@CameronVerto I don't have any strong opinions either way to be honest.

The answer to the original question is to use the filter as described.

Adding custom image sizes to the admin is covered in the add_image_size documentation here.

Perhaps there is an argument that declaring a custom image sizes' human readable name, could be done within the add_image_size function, thus making it available in the admin. However, I think that conversation is outside the scope of the Gutenberg Issues forum, and relates more to core WP functionality.

@muzKore
Copy link

muzKore commented May 28, 2019

I am facing a similiar issue. I to thought that by adding custom image sizes using add_image_size() would also include them in the drop down but that is not the case. In reflection, it makes sense as there are some sizes which you may not want to have appear. In reference to previous comments, previously uploaded files will not have the new sizes and will not appear in the dropdown. If they do, it may cause an error. Rule of thumb being if you add a new image size, regenerate the thumbnails using a plugin to make sure the adjusted image sizes are applied to all images.

FYI. To get it to work, I used:

`// 1. Add featured image sizes

add_image_size( 'medium-hard', 400, 400, true );
add_image_size( 'archive-card', 600, 400, true );
add_image_size( 'large-hard', 800, 800, true );
add_image_size( 'large-soft', 800, 800, false );
add_image_size( 'hero-container-width', 1200, 600, true );

// 2. Register the image sizes for use in Add Media modal
add_filter( 'image_size_names_choose', 'child_custom_sizes' );

function child_custom_sizes( $sizes ) {

return array_merge( $sizes, array(
	'medium-hard' => 			__( 'Medium (hard crop)' ),
	'archive-card' => 			__( 'Archive Card (soft crop)' ),
	'large-hard' => 			__( 'Large (hard crop)' ),
	'large-soft' => 			__( 'Large (soft crop)' ),
	'hero-container-width' => 	__( 'Hero Container (Hard drop)' ),
) );

}
`
After adding the code, I regenerated the thumbnails.
The interesting thing is that it worked fine in the classic editor but not in the Gutenberg editor. Maybe my mistake and please feel free to point it out.

@2shrestha22
Copy link

2shrestha22 commented Sep 8, 2019

Above method works for Gutenberg editor also.

@thetwopct
Copy link

Rule of thumb being if you add a new image size, regenerate the thumbnails using a plugin to make sure the adjusted image sizes are applied to all images.

You don't have to regenerate thumbnails to see the sizes in the select box for Gutenberg/Media Editor though. You only need to regenerate thumbnails to make old images display at the new sizes if you added them.

I was briefly stuck as to why image names weren't showing up in Gutenberg image block once I'd inserted the image_size_names_choose code, turns out I'd just forgotten to refresh the editor page. Sometimes its the simple things!

@youknowriad
Copy link
Contributor

Closing as this has been addressed by @NRDay

@paulschreiber
Copy link

This bit me, too. Would be great if the default behaviour included custom image sizes in the popup menu.

@davidallenlewis
Copy link

I'm finding that the image size select box for image blocks only shows up with images uploaded directly to the block. If I use existing images in the media library (with all those sizes available) I never see the image size chooser in the settings sidebar.

@ligne13
Copy link

ligne13 commented Nov 27, 2020

@uniondesign Same for me. Have you found an explanation ? a fix ?

thanks

@dylanjameswagner
Copy link

I'm finding that the image size select box for image blocks only shows up with images uploaded directly to the block. If I use existing images in the media library (with all those sizes available) I never see the image size chooser in the settings sidebar.

If you're able to create the new image crop with a plugin like Regenerate Thumbnails the crop will appear in the dropdown.

@eliasgomezsainz
Copy link

@dylanjameswagner that does not work. As @davidallenlewis says, you to upload the image from the Media Library for the new size to appear in the image block. Just tested it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Gallery Affects the Gallery Block - used to display groups of images [Block] Image Affects the Image Block Needs Technical Feedback Needs testing from a developer perspective.
Projects
None yet
Development

No branches or pull requests