post thumbnails - Use getthe_post_thumbnail with Custom Size & Crop

admin2025-06-05  3

We know that the_post_thumbnail() outputs the thumbnail & that the_post_thumbnail( array(100,100) ) outputs the thumbnail at a specified size.

And we know that we can use add_image_size( 'category-thumb', 300, 9999, $crop ); to add a custom image size which we can call using the_post_thumbnail('category-thumb') with scaling and cropping applied.

Is there a way to use the_post_thumbnail to crop an image when it's displayed?

set_post_thumbnail_size could help, but I'm asking specifically if there is a way to do this with the_post_thumbnail

This is relevant: the_post_thumbnail scaling not hard cropping

( if nothing's changed the answer is no )

We know that the_post_thumbnail() outputs the thumbnail & that the_post_thumbnail( array(100,100) ) outputs the thumbnail at a specified size.

And we know that we can use add_image_size( 'category-thumb', 300, 9999, $crop ); to add a custom image size which we can call using the_post_thumbnail('category-thumb') with scaling and cropping applied.

Is there a way to use the_post_thumbnail to crop an image when it's displayed?

set_post_thumbnail_size could help, but I'm asking specifically if there is a way to do this with the_post_thumbnail

This is relevant: the_post_thumbnail scaling not hard cropping

( if nothing's changed the answer is no )

Share Improve this question edited Dec 8, 2018 at 22:36 admcfajn asked Jan 10, 2018 at 3:53 admcfajnadmcfajn 1,3262 gold badges13 silver badges30 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

No, there's not a way to do this by using the_post_thumbnail(), neither it's recommended.

What you are looking for is cropping the images on the fly. This will cost heavy server resources, especially when you have a lot of images to work with.

But in theory, to do so, you can make a script that takes an image as input, crops the image using PHP, and then returns the image data without saving the actual file. But again, it's expensive.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749115101a316490.html

最新回复(0)