2017-06-06 56 views
0

試圖觸發與jQuery的AJAX調用uploadcare PHP函數,我得到的一切工作正常,除了用戶選擇裁剪區域。它作物的權利理性,但默認爲左上所有的時間。Uploadcare不正確裁剪

我缺少的是通過對用戶選擇的作物面積?

下面是運行腳本

$(function() { 
    $('#avatar-uc').each(function() { 
    $("#avatar-uc").find('.uploadcare-widget-button-open').html('<i class="fa fa-camera"></i> Edit Photo'); 
    $("#avatar-uc").find('.uploadcare-widget-button-remove').html('<i class="fa fa-camera"></i> Edit Photo'); 
     WidgetResetAvatar( 
     uploadcare.SingleWidget($(this).children('input')) 
    ); 
}); 
}); 
function WidgetResetAvatar(widget) { 
    widget.onChange(function(file) { 
    if (file) { 
     file.done(function(fileInfo) { 
     $.ajax({ 
      url: '/asset/create/avatar', 
      method: 'POST', 
      disablePreview: true, 
      headers: { 'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')}, 
      data: {uuid: fileInfo.uuid}, 
     }) 
     .done(function(data) { 
      $('#avatarPhoto').css('background-image', 'url("'+data.avatar_url+'")') 
     }); 
     }); 
    } 
    widget.value(null) 
    }); 
} 

jQuery的代碼和PHP函數

public function CreateAvatar(Request $request) 
{ 
if (!Auth::check()) { 
    return Response::json(array('message' => 'not logged in')); 
} 

$user = Auth::user(); 

if ($request->ajax()) { 
    if (!empty($request->uuid)) { 
     $api = app()->uploadcare; 
     $original_file = $api->getFile($request->uuid); 
     $cropped_file = $original_file->crop(150,150)->copy(); 
     $cropped_file->store(); 
     $cropped_file_url = $cropped_file->data['original_file_url']; 
     $upload_url = "https://ucarecdn.com"; 
     $remove_upload_care_url = ""; 
     $cropped_file_path = str_replace($upload_url, 
$remove_upload_care_url, $cropped_file_url); 
    } 
    else { 
     $cropped_file_path = ""; 
    } 

    $user->avatar = $cropped_file_path; 
    $user->save(); 

    return Response::json(['avatar_url' => $cropped_file_url]); 
} 
} 
+0

又是什麼的[PHP](https://www.youtube.com/watch?v=jofNR_WkoCE)說什麼? – Xorifelse

回答

0

出於某種原因,作物()功能不接受裁剪區域的座標,只是居中與否(見the code)。

最簡單的方法是構建URL by hand。將PR發送給圖書館以接受座標的獎勵積分。