$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>post thumbnails - Use getthe_post_thumbnail with Custom Size & Crop|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

post thumbnails - Use getthe_post_thumbnail with Custom Size & Crop

matteradmin10PV0评论

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.

Post a comment

comment list (0)

  1. No comments so far