Transformations on upload
coxlr opened this issue · comments
Is it possible to perform image transformations on upload? I have followed the Cloudinary docs, and added the options array to the upload call, but when trying to perform transformations, I receive an error.
My requested looks like this:
Cloudinary::upload($request->file('file')->getRealPath(), [
'folder' => 'avatar',
'transformation' => [
'width' => 100,
'height' => 100,
]
])->getSecurePath();
But this give the error:
ErrorException Array to string conversion
Illuminate\Foundation\Bootstrap\HandleExceptions::handleError
vendor/cloudinary/cloudinary_php/src/Utils/ArrayUtils.php:136
I have also tried the following:
Cloudinary::upload($request->file('file')->getRealPath(), [
'folder' => 'avatar',
'transformation' => [
[
'width' => 100,
'height' => 100,
]
]
])->getSecurePath();
Which gives the same error.
And also
Cloudinary::upload($request->file('file')->getRealPath(), [
'folder' => 'avatar',
'width' => 100,
'height' => 100,
])->getSecurePath();
But only the folder gets used and the width and height are not passed.
Hello @coxlr Looking into this right now.
@coxlr Just fixed this issue. Please update the package to the latest release.
Now, you can perform your image transformations on upload like you wanted:
You need to use the transformation key like so:
Cloudinary::upload($request->file('image')->getRealPath(), [
'folder' => 'avatar',
'transformation' => [
'width' => 100,
'height' => 100
]
])->getSecurePath();
Furthermore, you can make the resizing uniform by passing the crop
option to it like so:
Cloudinary::upload($request->file('image')->getRealPath(), [
'folder' => 'avatar',
'transformation' => [
'width' => 100,
'height' => 100,
'crop' => 'limit'
]
])->getSecurePath();
Awesome thank you. It works perfectly now.
Thanks for looking in to this so quickly.