Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add server-side crop a photo #305

Closed
Tracked by #218
teolemon opened this issue Nov 29, 2021 · 7 comments · Fixed by #309
Closed
Tracked by #218

Add server-side crop a photo #305

teolemon opened this issue Nov 29, 2021 · 7 comments · Fixed by #309

Comments

@teolemon
Copy link
Member

teolemon commented Nov 29, 2021

What

Part of

@teolemon teolemon changed the title Server-side crop a photo https://openfoodfacts.github.io/api-documentation/#jump-4WRITERequests-Cropaphoto Add server-side crop a photo Nov 29, 2021
@monsieurtanuki
Copy link
Contributor

@teolemon What is imgid?
Capture d’écran 2021-12-04 à 16 15 04

@teolemon
Copy link
Member Author

teolemon commented Dec 4, 2021

imgid you can find in the request, it's a unique id assigned to uploaded images, regardless of whether they are selected or not. You apply a rotation to a raw image id, and you place it in id like front_fr (which is a selection)
https://world.openfoodfacts.org/api/v0/product/3017620422003.json?fields=images

https://world.openfoodfacts.org/product/3760284870115/tiramisu-patissier
https://world.openfoodfacts.org/images/products/376/028/487/0115/1.jpg (1 is imgid)
https://world.openfoodfacts.org/images/products/376/028/487/0115/front_fr.8.full.jpg (front_fr is id, the 8 gets assigned automatically)

@monsieurtanuki monsieurtanuki self-assigned this Dec 4, 2021
@monsieurtanuki
Copy link
Contributor

There's probably something wrong in product_image_crop.pl, or in the way I expect the parameters to work:

What's wrong?

@teolemon
Copy link
Member Author

teolemon commented Dec 6, 2021

If you want to crop again an already cropped image like you do you need to start from the source image, get the current cropping coords if you want to expose them to the user, and apply the new crop coords to the original image (1.jpg)

@monsieurtanuki
Copy link
Contributor

I've tried from scratch on an existing product that did not have a front_de image.

Btw how would I get the current cropping coords?

@teolemon
Copy link
Member Author

teolemon commented Dec 6, 2021

monsieurtanuki added a commit to monsieurtanuki/openfoodfacts-dart that referenced this issue Dec 7, 2021
Impacted files:
* `api_addProductImage_test.dart`: added a test for `OpenFoodAPIClient.setProductImageCrop`; minor refactoring
* `ImageHelper.dart`: added methods `getProductImageRootUrl` and `getProductImageFilename`; minor refactoring
* `JsonHelper.dart`: populated crop fields of `ProductImage` for product `'images'`; minor refactoring
* `openfoodfacts.dart`: added method `setProductImageCrop`; minor refactoring
* `ProductHelper.dart`: minor refactoring
* `ProductImage.dart`: added crop fields `coordinatesImageSize`, `x1`, `y1`, `x2` and `y2` to `ProductImage`
@monsieurtanuki monsieurtanuki linked a pull request Dec 7, 2021 that will close this issue
@monsieurtanuki
Copy link
Contributor

I found out what was missing: query parameter coordinates_image_size=full. With that parameter the crop coordinates are on the full uploaded image, not its "400-max" version.
I've just committed a code that works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants