Archived topic
Adjusting crop of image thumbnails
3 replies · Started by Matthew on February 7, 2020
Hi
I am using the below function to crop the featured images when they are displayed on the archive pages
add_filter( 'generate_blog_image_attributes','tu_variable_image_sizes' );
function tu_variable_image_sizes( $atts ) {
// Set up our conditional
if ( is_post_type_archive( 'figures' ) || is_tax( 'figurecategory') ) {
$atts[ 'width' ] = 300;
$atts[ 'height' ] = 300;
$atts[ 'crop' ] = true;
}
// Return our options
return $atts;
}
Which works and crops nicely. But it's cropping in a position of center center. I would like to crop from the top down.
I know you can register new image sizes with the below code, but can you do something similar in the above function?
//* Register Image Sizes
add_image_size( 'figurethumb', 300, 300, array( 'center', 'top' ) );
Thanks,
Matt
Hi Matt,
Our current resizer doesn't work like that, unfortunately.
However, we're ditching the current resizer in the next version, so your add_image_size code is the way to go.
To use it, simply remove your width/height values in the Customizer, and do this:
add_filter( 'generate_page_header_default_size', function( $size ) {
return 'figurethumb';
} );
This is how the resizer will work in the next version, except you'll be able to choose figurethumb as the image size in the Customizer.
Let me know if you need more info :)
Thanks Tom.
Will live with it for the moment and revisit again when the new version is out.
Cheers
Matt
No problem!