最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

functions - Can you put a condition on add_image_size() depending on the width of the uploaded image?

programmeradmin3浏览0评论

I just started to optimize the auto-scaling of images i upload on my wordpress (via Media tool). I added the desired set of custom sizes, which are working just fine. In example :

add_image_size( 'og', 400, 9999 );
add_image_size( 'xxl', 300, 9999 );
add_image_size( 'xl', 200, 9999 );
add_image_size( 'l', 250, 9999 );
add_image_size( 'm', 150, 9999 );
add_image_size( 's', 100, 9999 );

But now i’m wondering if there is a way to put a condition to add_image_size() ? Is it possible to use a set of add_image size only if the uploaded image is less than 150px ?

I’m trying to avoid the creation of very small versions of images that are destined to be big. As wordpress don't scale images up, the idea is to have a rule that does something like : if the file i'm uploading has a width <= 150px then use this additional set of add_image_size().

I’m a beginner in coding so this might not be the right way to do it and i’m open to any suggestion !

Thank you

发布评论

评论列表(0)

  1. 暂无评论