我将Cloudinary用作应用程序的图像存储,但是在转换图像时遇到问题。
我想要实现的是:
jpg
; 我目前的积分是:
const transformation = {
width: 1920, max_height: 1920, format: 'jpg', quality: 80
};
但不幸的是,此输出是方形图像...
我正在尝试使用if
,但我不知道该如何使用...看来编写文档始终是最难的事情...
希望您能帮助我找到正确的方法。我使用的是SDK,因此都是纯JavaScript。
答案 0 :(得分:0)
There isn't a max_height
parameter in the SDK when creating transformations, but you can achieve what you're looking for by setting both width
and height
to the maximum value you want to allow.
If you're getting a square output, it's because the default crop/resize mode is scale
, which produces an output in exactly the dimensions requested, but may result in the image being 'squashed' or 'stretched'.
What I think you're looking for here is something like this:
const transformation = {
width: 1920, height: 1920, format: 'jpg', quality: 'auto', crop: 'limit'
};
Which gives you a URL like this: https://res.cloudinary.com/demo/image/upload/w_1920,h_1920,f_jpg,q_auto,c_limit/bike.jpg
The 'limit' crop mode will scale the image down (not up) until it's smaller than 1920x1920, and will keep the original aspect ratio