Rework scaled dimensions and compression (#737)

* Rework scaled dimensions and compression

* Unbreak image / banner uploads

---------

Co-authored-by: Paul Frazee <pfrazee@gmail.com>
This commit is contained in:
Ollie H 2023-05-30 17:23:55 -07:00 committed by GitHub
parent deebe18aaa
commit 072682dd9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 175 additions and 238 deletions

View file

@ -4,7 +4,6 @@ import {ImageModel} from './image'
import {Image as RNImage} from 'react-native-image-crop-picker'
import {openPicker} from 'lib/media/picker'
import {getImageDim} from 'lib/media/manip'
import {getDataUriSize} from 'lib/media/util'
import {isNative} from 'platform/detection'
export class GalleryModel {
@ -24,13 +23,7 @@ export class GalleryModel {
return this.images.length
}
get paths() {
return this.images.map(image =>
image.compressed === undefined ? image.path : image.compressed.path,
)
}
async add(image_: RNImage) {
async add(image_: Omit<RNImage, 'size'>) {
if (this.size >= 4) {
return
}
@ -39,15 +32,9 @@ export class GalleryModel {
if (!this.images.some(i => i.path === image_.path)) {
const image = new ImageModel(this.rootStore, image_)
if (!isNative) {
await image.manipulate({})
} else {
await image.compress()
}
runInAction(() => {
this.images.push(image)
})
// Initial resize
image.manipulate({})
this.images.push(image)
}
}
@ -70,11 +57,10 @@ export class GalleryModel {
const {width, height} = await getImageDim(uri)
const image: RNImage = {
const image = {
path: uri,
height,
width,
size: getDataUriSize(uri),
mime: 'image/jpeg',
}