我在我的應用程式中使用了以下代碼,將圖片上傳到imagekit。 而且我正在使用這個官方軟體包
。 。 function uploadImage ($base64Img, $fileName, $folder, $h, $w, $aratio){
$imageKit = new ImageKit(
"public_key,
"private_key"。
"urlEndpoint"
);
$config = [
'file' => $base64Img, //imageconverted to Base64
'fileName' => $fileName,
'檔案夾' => $folder, //檔案夾名稱
"transformation" => array(
陣列(
"高度" => "300" 。
"width" => "400"。
)
)
];
// if (isset($h) && isset($w)) {
// $config['transform'] = [
// [
// "高度" => $h,
// "width" => $w
// ]
// ];
// }
// if (isset($aratio)) {
// $config['transform'] = [
// [
// "ar" => '1:1',
// ]
// ];
// }
// 上傳圖片 - base64
$uploadFile = $imageKit->upload($config);
return($uploadFile->success->url);
}
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
根據官方檔案,回傳的URL應該是這樣的:
https://ik.imagekit.io/your_imagekit_id/endpoint/tr:h-300,w-400/my_file_name.jpg;
但我得到的是沒有轉換的url:
https://ik.imagekit.io/your_imagekit_id/endpoint/file_name.jpg
有人能幫我解決這個問題嗎?
uj5u.com熱心網友回復:
根據他們的檔案,他們回傳一個json回應:
{
"fileId" : "598821f949c0a938d57563bd"/span>。
"name": "file1.jpg",
"url": "https://ik.imagekit.io/your_imagekit_id/images/products/file1.jpg",
"thumbnailUrl": "https://ik.imagekit.io/your_imagekit_id/tr:n-media_library_thumbnail/images/products/file1.jpg",
"高度" : 300,
"width" : 200" 。
"size" : 83622。
"filePath": "/images/products/file1.jpg"。
"tags"。["t-shirt", "round-neck", "sale2019"】。]
"isPrivateFile" : false,
"customCoordinates" : null,
"fileType": "影像"
現在根據你使用的軟體包的檔案,你可以使用url生成方法生成一個帶有轉換的url:
$imageURL = $imageKit->url(array(
"path" => "/default-image.jpg"。
"transformation" => array(
array(
"height" => "300"。
"width" => "400",
)
)
));
來源。https://github.com/imagekit-developer/imagekit-php#url-generation
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/332462.html
標籤:
