programing

wpget image 편집기 이미지 저장 안 함

css3 2023. 10. 12. 23:25

wpget image 편집기 이미지 저장 안 함

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";

  }

}

이 함수는 "확인"을 반환하지만 대상 디렉터리는 비어 있고 이미지가 없습니다.

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과 같이 기록할 수 있는 권한이 있어야 합니다.

언급URL : https://stackoverflow.com/questions/21672930/wp-get-image-editor-not-saving-image