【问题标题】:WordPress is not creating custom image sizesWordPress 没有创建自定义图像大小
【发布时间】:2014-08-13 15:21:46
【问题描述】:

我有一个functions.php 文件,我在其中定义了一些自定义图像大小,以便在上传图像时由 WP 创建。

if ( function_exists( 'add_image_size' ) ) {

    // Thumbnail Size
    add_image_size('image-preview', 300);

    // Desktop 2:1
    add_image_size('image-desktop', 1920);
    add_image_size('image-desktop-crop', 1920, 960, true);

    // Tablet 8:5
    add_image_size('image-tablet', 1536);
    add_image_size('image-tablet-crop', 1536, 960, true);

    // Mobile Portrait 8:5
    add_image_size('image-mobile-portrait', 768);
    add_image_size('image-mobile-portrait-crop', 768, 480, true);

    // Mobile Landscape 2:1
    add_image_size('image-mobile-landscape', 960);
    add_image_size('image-mobile-landscape-crop', 960, 480, true);

}

当我转储一个图像对象时,我会得到类似的东西:

array(39) {
["image-preview"]=>
  string(75) "https://dev.xxxxxxxxxxxxx.com/wp-content/uploads/2014/08/BW-divider_1536x960px.jpg"
  ["image-preview-width"]=>
  int(300)
  ["image-preview-height"]=>
  int(187)
  ["image-desktop"]=>
  string(75) "https://dev.xxxxxxxxxxxxx.com/wp-content/uploads/2014/08/BW-divider_1536x960px.jpg"
  ["image-desktop-width"]=>
  int(1536)
  ["image-desktop-height"]=>
  int(960)
  ["image-desktop-crop"]=>
  string(75) "https://dev.xxxxxxxxxxxxx.com/wp-content/uploads/2014/08/BW-divider_1536x960px.jpg"
  ["image-desktop-crop-width"]=>
  int(1536)
  ["image-desktop-crop-height"]=>
  int(960)
  ["image-tablet"]=>
  string(75) "https://dev.xxxxxxxxxxxxx.com/wp-content/uploads/2014/08/BW-divider_1536x960px.jpg"
  ["image-tablet-width"]=>
  int(1536)
  ["image-tablet-height"]=>
  int(960)
  ["image-tablet-crop"]=>
  string(75) "https://dev.xxxxxxxxxxxxx.com/wp-content/uploads/2014/08/BW-divider_1536x960px.jpg"
  ["image-tablet-crop-width"]=>
  int(1536)
  ["image-tablet-crop-height"]=>
  int(960)
  ["image-mobile-portrait"]=>
  string(75) "https://dev.xxxxxxxxxxxxx.com/wp-content/uploads/2014/08/BW-divider_1536x960px.jpg"
  ["image-mobile-portrait-width"]=>
  int(768)
  ["image-mobile-portrait-height"]=>
  int(480)
  ["image-mobile-portrait-crop"]=>
  string(75) "https://dev.xxxxxxxxxxxxx.com/wp-content/uploads/2014/08/BW-divider_1536x960px.jpg"
  ["image-mobile-portrait-crop-width"]=>
  int(768)
  ["image-mobile-portrait-crop-height"]=>
  int(480)
  ["image-mobile-landscape"]=>
  string(75) "https://dev.xxxxxxxxxxxxx.com/wp-content/uploads/2014/08/BW-divider_1536x960px.jpg"
  ["image-mobile-landscape-width"]=>
  int(960)
  ["image-mobile-landscape-height"]=>
  int(600)
  ["image-mobile-landscape-crop"]=>
  string(75) "https://dev.xxxxxxxxxxxxx.com/wp-content/uploads/2014/08/BW-divider_1536x960px.jpg"
  ["image-mobile-landscape-crop-width"]=>
  int(768)
  ["image-mobile-landscape-crop-height"]=>
  int(480)
}

如您所见,它创建了具有正确宽度和高度的图像大小,但不是新的图像文件。相反,每个 URL 路径似乎都完全相同,这使得整个事情变得有点无用。我以前从来没有遇到过这个问题。

我正在使用高级自定义字段插件来上传我的图片。我认为这是一个 WP 问题。

我正在使用 WP 版本 3.9.2 - 这篇文章的最新版本。

知道这里会发生什么吗?

谢谢, 米奇。

【问题讨论】:

    标签: php wordpress wordpress-theming


    【解决方案1】:

    显然服务器没有 PHP 的 GD 图像库。 WP 似乎在这方面默默地失败了,只是为每次调整大小提供相同的图像。

    http://php.net/manual/en/book.image.php

    我的开发人员安装了 GD 图像库,我安装了重新生成缩略图插件以获取所有最新定义的尺寸。

    https://wordpress.org/plugins/regenerate-thumbnails/

    希望这对将来的人有所帮助。

    【讨论】:

      猜你喜欢
      • 2020-07-15
      • 2021-10-17
      • 2013-10-06
      • 2017-06-01
      • 1970-01-01
      • 2014-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多