How can I make JPEG uploads stay under a fixed file size like 300 KB?
Asked 12/24/2016
6 views
2 answers
0
I’m building an Android app that captures photos and uploads them to a server. I’ve been saving JPEGs at about 50% quality, but newer phones with higher resolutions can still produce files larger than 1 MB. I need uploads to stay under a limit such as 300 KB. Is there a practical way to compress a JPEG to a target file size, and is this the right approach?
Originally by Photography Stack Exchange contributor. Source · Licensed CC BY-SA 4.0
Photography Stack Exchange contributor
9y ago
2 Answers
1
Scenario: I have an android app which captures images and sends over to a server. Till now I had been setting 50% quality. But with high end phones with better sensors and resolutions even with that quality images end up with a size greater than a MB.
If you apply compression of any kind with the constraint being the final file size then you will ALWAYS suffer data loss and hence quality loss. The simple act of choosing to compress the files in this way defines the final level of detail possible, so your choice in compressing in this way guarantees that higher quality images will likely be compromised more.
However, I would personally not worry about the alleged quality loss for higher MP phones. Simply having more MP does not generally produce useful detail. The optics are limited by other factors and the high MP counts are to a large extent just a marketing gimmick.
If i decrease quality lower end cameras will suffer and I can't afford to push 1 MB image.
The obvious solution is to not send it that way, but to save to a card and transfer the card's data using a card reader later, perhaps sending the final files to the mystery server over e.g. you home broadband connection which may have better speeds and costs.
So, I am looking for a way to compress image with a size limit, say 300 KB.
I don't use Android so I've no app to tell you. On a PC I'd use something like ImageMagick ( e.g. this question https://stackoverflow.com/questions/6917219/imagemagick-scale-jpeg-image-with-a-maximum-file-size ).
If you're a developer of an Android app then you need to ask how to save files to specific size constraints on the appropriate StackExchange forum.
In your case if possible save the files to your SD card and then read them to a laptop or desktop computer and batch convert them with ImageMagick. Sounds long winded but if you do it regularly then it will become quite trivial with practice.
Originally by user46861. Source · Licensed CC BY-SA 4.0
user46861
9y ago
0
Generated from our catalog & community — verify before relying on it.
A fixed JPEG file-size limit is possible, but the tradeoff is unavoidable: to hit a target like 300 KB, you must throw away image data, so some images will lose more detail than others.
JPEG “quality” is not a direct file-size control. The same quality setting can produce very different sizes depending on resolution and scene detail. Higher-resolution phones often need more than just a lower quality setting.
The practical approach is usually:
- Resize the image to a sensible upload resolution first.
- Then apply JPEG compression.
- If needed, iteratively lower quality until the file is under your limit.
This is generally better than only lowering JPEG quality, because very large images waste bytes even when heavily compressed.
Also, don’t assume higher megapixel phones are always delivering proportionally more useful detail; small mobile optics often limit the real benefit. So reducing resolution for upload is often acceptable.
In short: yes, you can target a maximum size, but the right method is usually a combination of downsampling and JPEG compression rather than quality reduction alone.
Recommended products
UniqueBot
AI9y ago
Your Answer
Related Questions
Why won't my JPEG get smaller enough for web use?
Can Photoshop save a JPEG to an exact file size in MB?
Why can two 2000×2000 JPEGs saved at the same quality have drastically different file sizes?
How can I sharpen tiny thumbnails in Photoshop while keeping JPEG file size low?
How can I resize and export a JPEG to meet a photo contest's pixel and file-size requirements?