Skip to content

Commit

Permalink
Generate 101 images to see how JPEG quality impacts the result
Browse files Browse the repository at this point in the history
  • Loading branch information
rocboronat committed Jun 8, 2019
1 parent 215188a commit 39a0064
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/test/java/JpegCompressorTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import com.fewlaps.slimjpg.core.util.JpegCompressor;
import file.BinaryFileWriter;
import org.junit.Test;

import java.io.File;
import java.io.IOException;

public class JpegCompressorTest extends BaseTest {

private static final String OUT_DIRECTORY = "out/jpeg-qualities/";

@Test
public void useAllJpegQualities() throws IOException {
JpegCompressor compressor = new JpegCompressor();
byte[] image = getBytes(AVATAR);

File directory = new File(OUT_DIRECTORY);
directory.mkdirs();
BinaryFileWriter writer = new BinaryFileWriter();

for (int quality = 0; quality <= 100; quality++) {
long start = System.currentTimeMillis();

byte[] result = compressor.writeJpg(image, quality, false);

long time = System.currentTimeMillis() - start;
System.out.println("Compressing image in quality " + quality + " took " + time + "ms");

writer.write(result, OUT_DIRECTORY + "quality-" + quality + ".jpg");
}
}
}

0 comments on commit 39a0064

Please sign in to comment.