Skip to content

Commit

Permalink
fix resizing issue on ios
Browse files Browse the repository at this point in the history
  • Loading branch information
haileyok committed Feb 23, 2024
1 parent 864f8ee commit 8d41c45
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/lib/media/manip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,23 @@ interface DoResizeOpts {
}

async function doResize(localUri: string, opts: DoResizeOpts): Promise<Image> {
// We should run the first iteration outside of the loop. This is the only one that should resize the image and the
// loop can deal with lowering the quality if needed. Iterating on the resize causes problems on iOS
let resizeRes = await manipulateAsync(
localUri,
[{resize: {height: opts.height, width: opts.width}}],
{format: SaveFormat.JPEG, compress: 1},
)

for (let i = 0; i < 9; i++) {
const quality = 1 - 0.1 * i
// TODO We have a `mode` in react-native-image-resizer. What is this and do we need it here? Can we safely remove
// this option? Is it used?
const resizeRes = await manipulateAsync(
localUri,
[{resize: {height: opts.height, width: opts.width}}],
{format: SaveFormat.JPEG, compress: quality},
)
if (i > 0) {
const quality = 0.9 - 0.1 * i
resizeRes = await manipulateAsync(localUri, [], {
format: SaveFormat.JPEG,
compress: quality,
})
}

// @ts-ignore Size is available here, typing is incorrect
const info: FS.FileInfo & {size: number} = await getInfoAsync(
resizeRes.uri,
Expand Down

0 comments on commit 8d41c45

Please sign in to comment.