Skip to content
Snippets Groups Projects
Unverified Commit 9dadb32e authored by Sebastian's avatar Sebastian
Browse files

When compressing images to <32K, try lower quality values if necessary

parent 81183bbb
No related branches found
No related tags found
1 merge request!386Improve image compression
Pipeline #17522 passed
......@@ -28,11 +28,6 @@
<option name="JD_ALIGN_EXCEPTION_COMMENTS" value="false" />
</JavaCodeStyleSettings>
<JetCodeStyleSettings>
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
<value />
</option>
<option name="NAME_COUNT_TO_USE_STAR_IMPORT" value="2147483647" />
<option name="NAME_COUNT_TO_USE_STAR_IMPORT_FOR_MEMBERS" value="2147483647" />
<option name="ALLOW_TRAILING_COMMA" value="true" />
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</JetCodeStyleSettings>
......
......@@ -64,8 +64,8 @@ class ImageCompressorImpl @Inject internal constructor() : ImageCompressor {
val scaled = if (factor != 1) scaleDown(withoutAlpha, factor) else withoutAlpha
// After that, compress image. Try with maximum quality and reduce until we can compress below
// a size of [MAX_IMAGE_SIZE]. We try quality levels 100, 90, ..., 20, 10.
for (quality in 100 downTo 1 step 10) {
// a size of [MAX_IMAGE_SIZE]. We try quality levels 100, 90, ..., 20, 10, 9, 8, ..., 2, 1.
for (quality in (100 downTo 1 step 10) + (9 downTo 1 step 1)) {
val jpgWriter = ImageIO.getImageWritersByFormatName("jpg").next()
jpgWriter.output = ImageIO.createImageOutputStream(out)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment