uploadcare / pyuploadcare

Build file handling in minutes. Upload or accept user-generated content, store, transform, optimize, and deliver images, videos, and documents to billions of users.
https://uploadcare.com/
MIT License
127 stars 31 forks source link

Update and refactor /transformations/image.py #267

Closed rsedykh closed 7 months ago

rsedykh commented 1 year ago

Honestly, I don't like that we have to mirror URL API in the lib. Isn't there a more elegant way?

If not (or not now), let's reorder it to mirror the URL API structure better.

Changes/comments:

New stuff since the last update:

evgkirov commented 9 months ago

From https://uploadcare.com/docs/transformations/image/compression/#operation-format:

Alternatively, you can use the -/format/ operation to convert an image to one of the following formats:

But there's no avif listed in this section.

KamillaGarifullina commented 9 months ago

But there's no avif listed in this section.

This option is not available because it cannot be done that way.

evgkirov commented 9 months ago

CropAlignment: syntax is more than this; see https://uploadcare.com/docs/transformations/image/resize-crop/#operation-crop

Alignment is actually ok, you can set arbitrary position like this:

ImageTransformation().crop(
    width=640,
    height=480, 
    offset_x=50,
    offset_y="20%"
)

However, I can't see a way to "Crop by ratio" using ImageTransformation

KamillaGarifullina commented 9 months ago

However, I can't see a way to "Crop by ratio" using ImageTransformation

Here https://uploadcare.com/docs/transformations/image/resize-crop/#operation-crop-aspect-ratio is described how to make a ratio crop. Is this suitable for your task?

evgkirov commented 8 months ago

Yes.

But I've meant is that it's not supported by the library (yet!)

evgkirov commented 8 months ago

Isn't there a more elegant way?

It is the more elegant way. This provides a nice pythonic interface to set image effects.

The downside is that yes, it must be kept in sync with the URL API.

evgkirov commented 8 months ago
evgkirov commented 8 months ago

I wanted to update https://pyuploadcare.readthedocs.io/en/latest/core_api.html with the information about the added methods and... as it turns out,ImageTransformation is completely undocumented there.

I don't think it makes sense to write that part of the documentation by hand now. It should be automatically generated from the source code.

I think it's beyond the scope of this particular issue.

rsedykh commented 8 months ago

Let's document the existence of this feature and explain where to look for details.

evgkirov commented 8 months ago

explain where to look for details

You mean the source code for now?

rsedykh commented 8 months ago

You mean the source code for now?

Yes. And link to the /docs.