-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate 101 images to see how JPEG quality impacts the result
- Loading branch information
1 parent
215188a
commit 39a0064
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
} |