apoorv-2204

apoorv-2204

We have a service in production where we accept documents from users/clients
mainly: jpeg, png and pdf. And there are several of this file provided by client to fulfill the requirements.

The issues is when these files are needed to be send over email. with email size limit of 25 mb , the mail fails as of SendGrid services

I want to compress the incoming images png jpeg and pdf
But I don't want to loss quality, and they should be at least legible

What should I use what lib?
anything existing in elixir eco

Showing Posts 1 to 10

kip

kip

ex_cldr Core Team

Images, including jpeg and png, already contain compressed data so I would be surprised if they will compress significantly to get you under the 25mb limit if you’re already over it. I typically find a compressed jpeg/png image is only about 10% smaller than the original image.

apoorv-2204

apoorv-2204 OP

i have seen that,we can further compress jpeg, and png without losing quality as much

kip

kip

ex_cldr Core Team

Your original message says “lossless”. Higher jpeg/png compression (ie lower quality) is not lossless. Can you be a bit more specific about your requirements?

dimitarvp

dimitarvp

I simply searched for “optimize image api” and drowned in results. :person_shrugging:

As for lossless / lossy, IMO any image that’s 25MB is way too big. Though I don’t know your scenario, maybe you are working with galactic deep-field assembled images. :smiley:

mindok

mindok

As @kip has mentioned, JPG compression is lossless.

You can experiment with image editors or command line tools to get a sense of what loss you can get away with without breaking the use case, and it highly depends on the type of image. You typically have two variables to play with - image dimensions (i.e. resampling the image to make it smaller - depending on the types of image, some interpolation algorithms can be better than others), and a “quality” parameter. Due to the way JPG compression works, you can generally compress more when you have smooth gradients (e.g. skin tones with shadows), whereas lots of sharp colour changes (e.g. screenshots) tend to look terrible when heavily compressed.

PNG compression can be lossless - it works really well for screenshots where you have big blocks of the same colour. Generally it’s a tradeoff between computation time and compression.

PDF compression is complex - I’d set aside a good week for research and testing if you are going down that path. It can involve things like font stripping, embedded image compression etc, etc. I’ve gone down that rabbit hole and there are no easy answers. There are PDF compression services that can help, but I found nothing I would be happy to embed in my stack.

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

You’ve got some solid answers in the compression front so I’ll do the other angle: see if you can change the requirement to allow links to files. There’s a reason companies that specialize in document sharing don’t email them, and instead do links.

harrisi

harrisi

You got PNG and JPEG mixed up here - JPEG is (typically) lossy, PNG is lossless. Good info, though!

kevinschweikert

kevinschweikert

It should be the other way round. Our eye is much more sensitive for brightness than color changes. If the compression algorithm has to remove information in a gradient we tend to see it. A solid block of color in the other hand is easy to compress because it’s mostly a redundant information. With the contrast changes you are right because the compression algorithm reduces the “frequency” with something called a Discrete Cosine Transform (DCT). But there are more factors in the compression like color subsampling etc

AstonJ

AstonJ

I’ve updated the title though as pointed out by others it is not clear what you are after.

If you don’t want to lose quality then your best bet may be to zip the file and send that - this will not lose quality of the original file. If you compress image files themselves then, as pointed out already, that is lossy compression - however you can use tricks like converting PNGs to jpeg, reducing image size etc.

Also keep in mind many email providers have a limit on incoming email size as well.

apoorv-2204

apoorv-2204 OP

the image/pdf should be at least bare min legible.
I saw d/f algo like imagemagick ghostscript

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
peck
Hi everyone. My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
bradley
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
Alvinkariuki
How Can I Optimise Compile Time Dependencies I have been building an elixir application for about 2 years now. Many modules and files ha...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews