r/reactnative • • 8d ago

Should I convert from jpeg to webp for images saved in expo-file-system and firebase storage?

Seems like webp images are 30% smaller and offers no quality reduction, so should I convert to webp first before saving to reduce storage and increase speed?

For context, images would be photos uploaded by users

0 Upvotes

17 comments sorted by

4

u/davidbalbino 7d ago

tbh the format is the smaller win here. user photos come straight from the camera at like 4000px and a few MB, so resizing before upload saves way more than jpeg -> webp alone

expo-image-manipulator does both in one step:

const out = await manipulateAsync(uri, [{ resize: { width: 1600 } }], {
  compress: 0.8,
  format: SaveFormat.WEBP,
})

then upload out.uri. if you'd rather not touch it on the device, the Firebase Resize Images extension can generate webp versions server side. I think is worth keeping the original only if you really need full res later

2

u/Western_Cap_6934 8d ago

WebP can help, but the often-quoted 25-34 percent saving is for lossy encoding at comparable SSIM, not lossless conversion. Re-encoding a JPEG as lossy WebP can add artifacts. Compare actual uploads at the same dimensions and acceptable quality before converting everything, and include the encoding time in your speed comparison.

1

u/Miserable-Pause7650 7d ago

Thanks :) I suppose encoding time is only when uploading, but reading in my case is more frequent (like social media), so im more concerned about reading

1

u/Western_Cap_6934 7d ago

With many reads per upload, the one-time encoding cost is easier to amortize. Smaller WebP files can help uncached downloads, but decoding and image dimensions still affect display speed. For a feed, serve thumbnails sized for the view and use image caching rather than repeatedly loading full-resolution uploads.

1

u/Miserable-Pause7650 7d ago

So u mean WebP files require decoding time to display as well? And this decoding time is longer than jpeg? Yes Im aware that dimensions probably makes the biggest impact

1

u/Weak_Particular_5799 7d ago

yeah it's usually slower to decode. I tried one 2900x5367 photo with sharp on a laptop: at 1080px wide the webp was 20% smaller (212 KB vs 266 KB) but took ~58 ms to decode vs ~15 ms for the jpeg. Just resizing from the original 5.3 MB was the real win though. Phones will differ on the exact numbers.

1

u/Miserable-Pause7650 7d ago

Nice thanks for the input, real helpful :)

1

u/Western_Cap_6934 7d ago

Yes, JPEG needs decoding too. I meant that smaller downloads do not automatically mean faster display, not that WebP is always slower. The laptop result above is one data point, not a timing estimate for your app.

1

u/Miserable-Pause7650 5d ago

Thanks guys, updated my revenue cat package and now its all good :) Your advices helped me realize its revenue cat by looking at the config file generated

1

u/MobileXapps 8d ago

Resize before you think about the format. A phone photo is often 4000px wide and 3-5 MB, and if you show it at 1080px at most, scaling it down first saves far more than the JPEG to WebP switch.

I'd keep JPEG at a sensible quality after resizing, unless you're sure every place that reads these files handles WebP. If you want a thumbnail for lists, save a small one next to the full image instead of loading the big one everywhere.

1

u/Miserable-Pause7650 7d ago

Good advice :) the alternate thumbnail image is also a good advice!

1

u/anthony-ball 7d ago

For user photos the format matters less than the size. Most of the savings come from not uploading the 12MP camera original. Resize to around 1600-2000px on the long edge with expo-image-manipulator and compress around 0.7-0.8, and you're usually down to a few hundred KB. The manipulator can also save as webp, so since you're re-encoding anyway you don't pay for a second lossy pass by picking webp over jpeg. Just make sure everything else that reads those files, like a web admin, emails or thumbnails, handles webp.

1

u/Miserable-Pause7650 7d ago

Thanks for the tips :)

2

u/MortgageMelodic2282 8d ago

Is not doing it a problem? If so yes. If not no

2

u/therealswood2 8d ago

That is certainly an option.

Should you? How should we know?