强制WordPress创建图像缩略图


Force WordPress to create image thumbnails

目前,media.php的第378 -380行包含以下行:

// if the resulting image would be the same size or larger we don't want to resize it
if ( $new_w >= $orig_w && $new_h >= $orig_h && !$allow_resize)
    return false;

这显然对一个典型的设置很有意义,但是我在一个摄影网站上工作,管理员将上传非常高质量的jpg,它们是大尺寸缩略图的正确尺寸,但是图像质量对于web使用来说太高了。

本质上,我希望WordPress创建一个与原始大小相同的大缩略图(核心代码阻止它这样做)。我见过一些解决方案,但它们都涉及替换和破坏原来的,我不想这样做。

关于从哪里开始有什么建议吗?

在主题的functions.php中试试:

add_filter('image_resize_dimensions', 'filterCompress', 1, 6);
function filterCompress($foo, $orig_w, $orig_h, $dest_w, $dest_h, $crop) {
  if ( $orig_w == $dest_w && $orig_h == $dest_h ) {
        return array( 0, 0, 0, 0, (int) $orig_w, (int) $orig_h, (int) $orig_w, (int) $orig_h );
  }
  return null;
}

我这样做是基于WordPress 3.5.1,根据你的问题,我假设你使用的是不同的版本,但它仍然可能工作。