在Wordpress中强制最小图像尺寸

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在Wordpress中强制最小图像尺寸相关的知识,希望对你有一定的参考价值。

Add this snippet to your Wordpress theme's functions.php file to reject any image uploads that are below the specified dimensions.
  1. /**
  2.  * Enforce minimum image upload size.
  3.  */
  4. add_filter('wp_handle_upload_prefilter','handle_upload_prefilter');
  5.  
  6. function handle_upload_prefilter($file) {
  7. $img=getimagesize($file['tmp_name']);
  8. $minimum = array('width' => '640', 'height' => '480');
  9. $width= $img[0];
  10. $height =$img[1];
  11.  
  12. if ($width < $minimum['width'] ){
  13. return array("error"=>"Image dimensions are too small. Minimum width is {$minimum['width']}px. Uploaded image width is $width px.");
  14. } elseif ($height < $minimum['height']){
  15. return array("error"=>"Image dimensions are too small. Minimum height is {$minimum['height']}px. Uploaded image width is $width px.");
  16. } else {
  17. return $file;
  18. }
  19. }

以上是关于在Wordpress中强制最小图像尺寸的主要内容,如果未能解决你的问题,请参考以下文章

php 根据当前注册的图像尺寸(Wordpress),根据最小高度自动限制最小上传尺寸

从图像源中删除最后一个字符

Wordpress 的图像的“尺寸”属性是如何计算的?

php [自定义图像尺寸]添加自定义尺寸图像(上传媒体时的新尺寸)#wordpress #php

在 Pagelines Pro Wordpress 主题中指定 <img> 的图像尺寸

如何在 Android 的滚动视图中放大/更改子图像视图尺寸以使图像全尺寸