Hitting an exact file-size target when compressing photos on an Android device
A developer built an Android utility that compresses photos to exact size limits required by visa, job, and scholarship forms, without uploading images anywhere. Because WebView lacks a compress-to-byte-count API and JPEG quality does not map linearly to file size, the app uses a binary search over quality values to find the largest output under the target. If quality hits its floor, the image is downscaled in steps while keeping small text readable. The pipeline decodes at target size to avoid memory crashes, writes results to separate files so originals are preserved, and processes batches sequentially. PNG inputs are converted to JPEG when they lack transparency, otherwise they stay larger, and the app reports which path was taken.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.


Discussion (0)
Log in to join the discussion and vote.
Log in