I have the following code in my app to upload image to imagekit. And i'm using this official package
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' => $folder, //foldername
"transformation" => array(
array(
"height" => "300",
"width" => "400",
)
)
];
// if (isset($h) && isset($w)) {
// $config['transform'] = [
// [
// "height" => $h,
// "width" => $w
// ]
// ];
// }
// if (isset($aratio)) {
// $config['transform'] = [
// [
// "ar" => '1:1',
// ]
// ];
// }
// Upload Image - base64
$uploadFile = $imageKit->upload($config);
return($uploadFile->success->url);
}
According to the official docs the return url should be like this:
https://ik.imagekit.io/your_imagekit_id/endpoint/tr:h-300,w-400/my_file_name.jpg
;
But all I get is url without transformation:
https://ik.imagekit.io/your_imagekit_id/endpoint/file_name.jpg
Can anyone help me out on this ?
CodePudding user response:
According to their docs they return a json response:
{
"fileId" : "598821f949c0a938d57563bd",
"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",
"height" : 300,
"width" : 200",
"size" : 83622,
"filePath": "/images/products/file1.jpg",
"tags": ["t-shirt","round-neck","sale2019"],
"isPrivateFile" : false,
"customCoordinates" : null,
"fileType": "image"
}
Now according to the docs of the package you are using you can generate an url with transformation using the url generation method:
$imageURL = $imageKit->url(array(
"path" => "/default-image.jpg",
"transformation" => array(
array(
"height" => "300",
"width" => "400",
)
)
));
Source: https://github.com/imagekit-developer/imagekit-php#url-generation