about summary refs log tree commit diff
path: root/src/lib/media
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/media')
-rw-r--r--src/lib/media/manip.web.ts10
-rw-r--r--src/lib/media/picker.shared.ts7
2 files changed, 10 insertions, 7 deletions
diff --git a/src/lib/media/manip.web.ts b/src/lib/media/manip.web.ts
index 914b05d2e..bdf6836a1 100644
--- a/src/lib/media/manip.web.ts
+++ b/src/lib/media/manip.web.ts
@@ -117,9 +117,6 @@ function createResizedImage(
         return reject(new Error('Failed to resize image'))
       }
 
-      canvas.width = width
-      canvas.height = height
-
       let scale = 1
       if (mode === 'cover') {
         scale = img.width < img.height ? width / img.width : height / img.height
@@ -128,10 +125,11 @@ function createResizedImage(
       }
       let w = img.width * scale
       let h = img.height * scale
-      let x = (width - w) / 2
-      let y = (height - h) / 2
 
-      ctx.drawImage(img, x, y, w, h)
+      canvas.width = w
+      canvas.height = h
+
+      ctx.drawImage(img, 0, 0, w, h)
       resolve(canvas.toDataURL('image/jpeg', quality))
     })
     img.src = dataUri
diff --git a/src/lib/media/picker.shared.ts b/src/lib/media/picker.shared.ts
index 00b09c6b8..8bade34e2 100644
--- a/src/lib/media/picker.shared.ts
+++ b/src/lib/media/picker.shared.ts
@@ -4,6 +4,7 @@ import {
   MediaTypeOptions,
 } from 'expo-image-picker'
 import {getDataUriSize} from './util'
+import * as Toast from 'view/com/util/Toast'
 
 export async function openPicker(opts?: ImagePickerOptions) {
   const response = await launchImageLibraryAsync({
@@ -13,7 +14,11 @@ export async function openPicker(opts?: ImagePickerOptions) {
     ...opts,
   })
 
-  return (response.assets ?? []).map(image => ({
+  if (response.assets && response.assets.length > 4) {
+    Toast.show('You may only select up to 4 images')
+  }
+
+  return (response.assets ?? []).slice(0, 4).map(image => ({
     mime: 'image/jpeg',
     height: image.height,
     width: image.width,