Skip Navigation

[Resolved] Thumbnails in the same proportion and size

This thread is resolved. Here is a description of the problem and solution.

Problem:

Customer needed to get the thumbnails in the same proportion and size without distortion

Solution:

First you need to register the size of the thumbnails inside your child theme's functions.php file and define the crop option as true, eg.:

add_image_size( 'custom-size', '360', '200', true );

Then you can register it as an option so it appears in the GUI:

add_filter( 'image_size_names_choose', 'the_custom_sizes_as_registered_by_you' );
   
function the_custom_sizes_as_registered_by_you( $sizes ) {
    return array_merge( $sizes, array(
        'custom-size' => __( 'Custom Size' ),       
    ) );
}

Now whenever you pick your sizes using blocks, in the Image Settings, the custom size you created should be available in there and with the crop option enabled by default:

Relevant Documentation:

https://developer.wordpress.org/reference/hooks/image_size_names_choose/
https://developer.wordpress.org/reference/functions/add_image_size/

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Sao_Paulo (GMT-03:00)

This topic contains 1 reply, has 2 voices.

Last updated by Mateus Getulio 1 year, 1 month ago.

Assisted by: Mateus Getulio.

Author
Posts
#2666907

How do I get the thumbnails in the same proportion and size without distortion?
It may be a cutout or crop.

Is there a similar example that we can see?
hidden link

What is the link to your site?
hidden link

#2666929

Mateus Getulio
Supporter

Languages: English (English )

Timezone: America/Sao_Paulo (GMT-03:00)

Hey there,

Thank you for contacting our support.

Can you try to add your custom image size using the WordPress function 'add_image_size': https://developer.wordpress.org/reference/functions/add_image_size/

First you need to register the size of the thumbnails inside your child theme's functions.php file and define the crop option as true, eg.:

add_image_size( 'custom-size', '360', '200', true );

Then you can register it as an option so it appears in the GUI:

add_filter( 'image_size_names_choose', 'the_custom_sizes_as_registered_by_you' );
  
function the_custom_sizes_as_registered_by_you( $sizes ) {
    return array_merge( $sizes, array(
        'custom-size' => __( 'Custom Size' ),       
    ) );
}

Now whenever you pick your sizes using blocks, in the Image Settings, the custom size you created should be available in there and with the crop option enabled by default:

PS:
- If the image is smaller, or the sizes are not registered to hook "image_size_names_choose", it won't work. You can read more here about the WordPress hook image_size_names_choose: https://developer.wordpress.org/reference/hooks/image_size_names_choose/
- Make sure to load your in add_image_size() after_setup_theme hook: https://developer.wordpress.org/reference/hooks/after_setup_theme/

Please give it a try and tell us the results.

Best,
Mateus