【问题标题】:wp get image editor not saving imagewp获取图像编辑器不保存图像
【发布时间】:2014-03-07 12:45:51
【问题描述】:

wp_get_image_editor() 在 localhost(mamp) 上调整大小并保存图像很好,但在服务器上它根本不工作(保存)没有错误,这是我的代码

function image_crop($url, $name){ 

  $image = wp_get_image_editor( $url );

  if ( ! is_wp_error( $image ) ) {

    $image->resize( 100, 140, true );

    $data = $image->save( $name.'_'.$id.'.png' );

  }

  if( ! is_wp_error( $data )  )
  {

      return "ok";

  }else{

      return "Error";

  }

}

此函数返回“ok”,但目标目录为空,没有图像。

【问题讨论】:

  • 这可能是由于您的文件夹权限。检查您的文件夹权限
  • 此文件夹获得 777 权限
  • 通过广泛可用的 GD 和/或 ImageMagick 库检查您的服务器端支持

标签: php wordpress image


【解决方案1】:

如果您想使用工具 wp_get_image 编辑器保存图片,您必须执行以下操作:

// load image object
// the best way to use picture path instead of url, as in the example below
$image = wp_get_image_editor( $_SERVER['DOCUMENT_ROOT'].'/wp-content/uploads/2015/10/image.png' );

// process image
if ( ! is_wp_error( $image ) ) {
    $image->resize( 100, 140, true );

    // save the root site irectory called new_image.png
    // use path to the folder where you want to save a picture
    $image->save( $_SERVER['DOCUMENT_ROOT'].'/new_image.png' );
}

您保存图片的文件夹必须有录制权限,例如755或777。

【讨论】:

    猜你喜欢
    • 2013-01-08
    • 2011-06-10
    • 2019-04-28
    • 1970-01-01
    • 2023-03-21
    • 2011-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多