I want to resize image. Some times when we upload small image want to resize.
How can I do it?
Eg - When we upload 250px * 190px
image I want to resize 450px * 200px
I used below code but it's not working:
add_image_size( 'img-fluid featured-purple-img', 475, 290, true ); // width, height, crop
Adding the Image Size is just the first step. To make it avaible in the Media Uploader use this code in your functions.php
add_filter( 'image_size_names_choose', 'my_custom_sizes' );
function my_custom_sizes( $sizes ) {
return array_merge( $sizes, array(
'img-fluid featured-purple-img' => __( 'New Custom Size Name' ),
) );
}
If you want to use the image size in a template, this will do the trick:
if ( has_post_thumbnail() ) {
the_post_thumbnail( 'img-fluid featured-purple-img' );
}
Also I'm not quite sure how a whitespace in the image name affects functionality
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.