Answer the question
In order to leave comments, you need to log in
How to resize images in wordpress?
Task: display a cropped image of a certain size (sizes are set in the admin panel in pixels).
I tried the_post_thumbnail() function,
but the image is not cropped, the proportions are preserved.
I looked for more options, found the wp_get_image_editor() function , which can resize and crop images, but it doesn’t need the image ID, but the path to it on the server, and the function also returns the path to the image on the server, so I had to add a little (I took as a basis image_make_intermediate_size() function ):the_post_thumbnail( array( 360, 360 ) );
function get_intermediate_size_image_src( $file, $width, $height, $crop = false ) {
if ( $width || $height ) {
$editor = wp_get_image_editor( $file );
if ( is_wp_error( $editor ) || is_wp_error( $editor->resize( $width, $height, $crop ) ) )
return false;
$resized_file = $editor->save();
if ( ! is_wp_error( $resized_file ) && $resized_file ) {
$upload_dir = wp_upload_dir();
return str_replace( $upload_dir[ 'basedir' ], $upload_dir[ 'baseurl' ], $resized_file[ 'path' ] );
}
}
return false;
}
add_image_size('square_small__crop', 360, 360, true);
Answer the question
In order to leave comments, you need to log in
I do a resize in ACDSEE, batch processing, then upload where necessary. I didn't look for an easier way.
I use timthumb
https://www.binarymoon.co.uk/projects/timthumb/
but this solution is not out of the box, though I don’t know the best option yet (
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question