Skip to content

Instantly share code, notes, and snippets.

View usamaasfar's full-sized avatar
🎯
Focusing

usamaasfar

🎯
Focusing
View GitHub Profile
@usamaasfar
usamaasfar / compress.js
Last active September 23, 2021 13:26
React Native Image Compress Based On Image Size
import * as ImageManipulator from 'expo-image-manipulator';
export default async function ImageCompress(image, { width, height }) {
const compressSizer = size => {
const MB = size / Math.pow(1024, 2);
if (Math.round(MB) === 0) return 1;
if (Math.round(MB) === 1) return 0.9;
if (Math.round(MB) === 2) return 0.8;
if (Math.round(MB) === 3) return 0.7;
if (Math.round(MB) === 4) return 0.6;