HTTP在Wordpress上上传图像时出错

时间:2018-07-30 00:03:23

标签: php wordpress imagick

我正在与Imagick合作,我不知道会发生什么,因为当我上传文件“ png”或“ jpg”时,它将返回:

  

错误HTTP

但是当我上传文件“ jpge”时,它可以正常工作。

这是functions.php上的代码:

  add_filter( 'wp_generate_attachment_metadata', 'generate_watermarked_image' );

function watermark_image( $filename, $upload_dir ) {

  $original_image_path = trailingslashit( $upload_dir['path'] ) . $filename;

  $image_resource = new Imagick( $original_image_path );
  $watermark_resource = new Imagick( get_stylesheet_directory() . '/images/logo.png' );
  $image_resource->compositeImage( $watermark_resource, Imagick::COMPOSITE_DEFAULT, 0, 0 );

  return save_watermarked_image( $image_resource, $original_image_path );

}

function save_watermarked_image( $image_resource, $original_image_path ) {

  $image_data = pathinfo( $original_image_path );

  $new_filename = $image_data['filename'] . '-watermarked.' . $image_data['extension'];

  $watermarked_image_path = str_replace($image_data['basename'], $new_filename, $original_image_path);

  if ( ! $image_resource->writeImage( $watermarked_image_path ) )
    return $image_data['basename'];

  unlink( $original_image_path ); // Because that file isn't referred to anymore

  return $new_filename;

}

对不起我的英语。

0 个答案:

没有答案