-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to specify compression quality #5
Comments
I just want to point out real quickly that imgscalr (Scalr class) only operates on BufferedImage instances which are pure, uncompressed image data -- the library itself has nothing to do with image compression, that is handled (typically) by the built in Java encoding libraries that most people access via the ImageIO library. That said, I am not sure what Play-scalr is doing; if it is actually reading and writing the compressed images, then I can understand this request and I redact my comment :) |
@thebuzzmedia Yes you're right The code in question is inside Play-scalr. The method Imgscalr operates on uncompressed image data and we don't apply compression so we can have bigger image when we scale down... which is a little weird 😄
It's a bad idea because the fact that the image is compressed is not always in metadata. try {
val iter = ImageIO.getImageWritersByFormatName(ext)
val writer = iter.next()
val iwp = writer.getDefaultWriteParam
iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT)
iwp.setCompressionQuality(.7F)
val output = new FileImageOutputStream(tmp)
writer.setOutput(output)
val iioImage = new IIOImage(resized, null, null)
writer.write(null, iioImage, iwp)
writer.dispose()
output.close()
tmp
} catch {
case e:UnsupportedOperationException =>
val tmp = File.createTempFile(Random.nextString(20), ext)
ImageIO.write(resized, ext.toUpperCase, tmp)
tmp
} |
When you're using Scalr with a compressed image the result is much bigger.
Somehow the compression is lost.
For example when I scale down a 750_500px compressed image (65Kb) to a 740_500px image, the result is an 800Kb image 😢
Reference: http://www.universalwebservices.net/web-programming-resources/java/adjust-jpeg-image-compression-quality-when-saving-images-in-java
Can we add a parameter
compressionQuality
(with default value 1.0F) togetRes
https://github.com/digiPlant/play-scalr/blob/master/app/se/digiplant/scalr/api/Scalr.scala#L65 ?A better way would be to preserve the compression quality of the image... maybe http://docs.oracle.com/javase/7/docs/api/javax/imageio/ImageWriteParam.html#MODE_COPY_FROM_METADATA
The text was updated successfully, but these errors were encountered: