Imagekit not returing transformed url

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 ?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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

Source: https://docs.imagekit.io/api-reference/upload-file-api/server-side-file-upload#response-code-and-structure-json

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


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x