-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
46a5ec6
commit 9ac0f70
Showing
6 changed files
with
53 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
import {manipulateAsync} from 'expo-image-manipulator'; | ||
import {ImageManipulator} from 'expo-image-manipulator'; | ||
import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; | ||
import type ImageManipulatorConfig from './type'; | ||
|
||
export default function getImageManipulator({fileUri, width, height, type, fileName}: ImageManipulatorConfig): Promise<FileObject> { | ||
return manipulateAsync(fileUri ?? '', [{resize: {width, height}}]).then((result) => ({ | ||
uri: result.uri, | ||
width: result.width, | ||
height: result.height, | ||
type, | ||
name: fileName, | ||
})); | ||
return ImageManipulator.manipulate(fileUri ?? '') | ||
.resize({width, height}) | ||
.renderAsync() | ||
.then((image) => image.saveAsync()) | ||
.then((result) => ({ | ||
uri: result.uri, | ||
width: result.width, | ||
height: result.height, | ||
type, | ||
name: fileName, | ||
})); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
import {manipulateAsync} from 'expo-image-manipulator'; | ||
import {ImageManipulator} from 'expo-image-manipulator'; | ||
import type ImageManipulatorConfig from './type'; | ||
|
||
export default function getImageManipulator({fileUri, width, height, fileName}: ImageManipulatorConfig): Promise<File> { | ||
return manipulateAsync(fileUri ?? '', [{resize: {width, height}}]).then((result) => | ||
fetch(result.uri) | ||
.then((res) => res.blob()) | ||
.then((blob) => { | ||
const resizedFile = new File([blob], `${fileName}.jpeg`, {type: 'image/jpeg'}); | ||
resizedFile.uri = URL.createObjectURL(resizedFile); | ||
return resizedFile; | ||
}), | ||
); | ||
return ImageManipulator.manipulate(fileUri ?? '') | ||
.resize({width, height}) | ||
.renderAsync() | ||
.then((image) => image.saveAsync()) | ||
.then((result) => | ||
fetch(result.uri) | ||
.then((res) => res.blob()) | ||
.then((blob) => { | ||
const resizedFile = new File([blob], `${fileName}.jpeg`, {type: 'image/jpeg'}); | ||
resizedFile.uri = URL.createObjectURL(resizedFile); | ||
return resizedFile; | ||
}), | ||
); | ||
} |