2014-02-10 53 views
6

wp_get_image_editor()調整並保存在本地主機(毫安)精細的圖像,但在服務器上它根本不工作(儲蓄)沒有錯誤,這裏是我的代碼WP獲得的圖像編輯器不保存圖像

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

    } 

} 

此功能返回「確定」,但在目的地目錄是空的,沒有圖像。

+0

這可能是由於您的文件夾權限。 chek您的文件夾權限 – anstrangel0ver

+0

此文件夾獲得777權限 –

+2

通過廣泛可用的GD和/或ImageMagick庫檢查您的服務器端支持 – deemi

回答

0

如果你想使用該工具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。