From 40c2ce20f3068614a1219ac7b41a9e50afa5d75e Mon Sep 17 00:00:00 2001 From: Antoine Piron Date: Wed, 10 Jun 2026 15:58:12 +0200 Subject: [PATCH] feat: resize images to max 1920px before upload Add expo-image-manipulator. In pickImage(), detect if image dimensions exceed 1920px and resize (keeping aspect ratio) + compress to JPEG 0.85. Previously only JPEG quality was set but dimensions were untouched. Co-Authored-By: Claude Sonnet 4.6 --- .../postiz-mobile/app/(tabs)/compose.tsx | 20 +++++++++++++++++-- artifacts/postiz-mobile/package.json | 1 + 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/artifacts/postiz-mobile/app/(tabs)/compose.tsx b/artifacts/postiz-mobile/app/(tabs)/compose.tsx index cdebd8c..513336f 100644 --- a/artifacts/postiz-mobile/app/(tabs)/compose.tsx +++ b/artifacts/postiz-mobile/app/(tabs)/compose.tsx @@ -4,6 +4,7 @@ import DateTimePicker from "@react-native-community/datetimepicker"; import AsyncStorage from "@react-native-async-storage/async-storage"; import * as Haptics from "expo-haptics"; import { Image } from "expo-image"; +import * as ImageManipulator from "expo-image-manipulator"; import * as ImagePicker from "expo-image-picker"; import { fetch as expoFetch } from "expo/fetch"; import { useLocalSearchParams } from "expo-router"; @@ -146,10 +147,25 @@ export default function ComposeScreen() { const result = await ImagePicker.launchImageLibraryAsync({ mediaTypes: ["images"], allowsEditing: false, - quality: 0.85, + quality: 1, }); if (!result.canceled && result.assets[0]) { - setImageUri(result.assets[0].uri); + const asset = result.assets[0]; + const MAX_DIM = 1920; + const w = asset.width ?? 0; + const h = asset.height ?? 0; + const needsResize = w > MAX_DIM || h > MAX_DIM; + if (needsResize) { + const landscape = w >= h; + const resized = await ImageManipulator.manipulateAsync( + asset.uri, + [{ resize: landscape ? { width: MAX_DIM } : { height: MAX_DIM } }], + { compress: 0.85, format: ImageManipulator.SaveFormat.JPEG } + ); + setImageUri(resized.uri); + } else { + setImageUri(asset.uri); + } setExistingMedia([]); } }; diff --git a/artifacts/postiz-mobile/package.json b/artifacts/postiz-mobile/package.json index 7e9d2a1..2a2fdf8 100644 --- a/artifacts/postiz-mobile/package.json +++ b/artifacts/postiz-mobile/package.json @@ -33,6 +33,7 @@ "expo-glass-effect": "~0.1.4", "expo-haptics": "~15.0.8", "expo-image": "~3.0.11", + "expo-image-manipulator": "~13.0.6", "expo-image-picker": "~17.0.9", "expo-linear-gradient": "~15.0.8", "expo-linking": "~8.0.10",