-
Notifications
You must be signed in to change notification settings - Fork 3.7k
feat: Add thumbnail support for receipts and improve image handling #84919
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
Changes from 1 commit
d6fa27a
35be2b4
23bb98f
6c74437
90397b1
af737d4
ddff150
8b0918c
f4cf69d
ecc9d6c
336ecb9
05b4b40
fd0e6fe
946ddbb
f8cac08
a3e143e
cbfb4f1
8e8bcf0
f24b70f
5beb1fa
6acd919
3b1ef08
49d3c60
512c481
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import {ImageManipulator, SaveFormat} from 'expo-image-manipulator'; | ||
| import ImageSize from 'react-native-image-size'; | ||
| import type {Orientation} from 'react-native-vision-camera'; | ||
| import cropOrRotateImage from '@libs/cropOrRotateImage'; | ||
|
|
@@ -78,5 +79,18 @@ function cropImageToAspectRatio( | |
| .catch(() => image); | ||
| } | ||
|
|
||
| /** | ||
| * Generate a low-resolution thumbnail from an image URI. | ||
| * Used on native to avoid decoding the full 12MP camera photo on the confirmation page. | ||
| */ | ||
| function generateThumbnail(sourceUri: string, maxWidth = 512): Promise<string | undefined> { | ||
kubabutkiewicz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Julesssss marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return ImageManipulator.manipulate(sourceUri) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We definitely should check this on Android and iOS both. I think I saw on my crappy Galaxy S8 that the image preview on confirmation page takes about 1 second to load without any resizing. But, also I think we can control the overall file size by tweaking the vision camera settings e.g. if we use |
||
| .resize({width: maxWidth}) | ||
| .renderAsync() | ||
| .then((image) => image.saveAsync({compress: 0.8, format: SaveFormat.JPEG})) | ||
| .then((result) => result.uri) | ||
Julesssss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .catch(() => undefined); | ||
kubabutkiewicz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| export type {ImageObject}; | ||
| export {calculateCropRect, cropImageToAspectRatio}; | ||
| export {calculateCropRect, cropImageToAspectRatio, generateThumbnail}; | ||
Uh oh!
There was an error while loading. Please reload this page.