WordPress - Cropping thumbnails without losing quality

混江龙づ霸主 提交于 2019-12-24 02:23:44

问题


I have a website on which there is a "shop" page. Each product has a thumbnail assigned to it.

I set a custom thumbnail size with this code:

if ( function_exists( 'add_image_size' ) ) { 
   add_image_size( 'products', 150, 84, true );
}

Cropping works fine, but when the image is too tall WordPress crops it to the "height" parameter and the final result is a thumbnail too narrow to look good.

Is there a way to make WordPress select a part of an image (150x84 px fragment) and use it as a thumbnail instead of resizing the image? It is important for thumbnails to stay at 150x84 px EXACTLY while not being too narrow or too short.


回答1:


I have found an answer.

Even if WordPress does crop images while using the function I used here, it may do it improperly until thumbnails are regenerated. Short answer is: WordPress cropped my images, but it was flawed due to thumbnails not being regenerated.

To regenerate them please use this plugin:

Regenerate Thumbnails




回答2:


You can select which part you want to crop.

You have to do it like this:

add_image_size('respuesta',320,200,array('center','center'));

If you want to crop the center of the image.

You can check the documentation to understand better this method.



来源:https://stackoverflow.com/questions/25383786/wordpress-cropping-thumbnails-without-losing-quality

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!