Closed ntkhanh closed 7 years ago
I don't have enough details to understand the issue you are encountering. Use of outputFormat
is not mandatory, unless you are using the toOutputStream
(or toOutputStreams
).
For your information, based on the information you've provided, I've attempted to reproduce what you've reported, by using the following code:
Thumbnails.of("source.png")
.scale(1)
.toFile("output.jpg");
The above code does not use outputFormat
, but is able to output a JPEG file based on the output file name provided to the toFile
method.
Please provide more details, such as a minimal amount code that can be used to reproduce the issue you have reported.
Thanks for your reply.
My program use Thumnailator for processing uploaded images and storing serveral copies with different size to GridFS server. I have tried Javaxt and have issue with image quality so I think Thumbnailator is much better.
However, I got an issue that Thumbnailator always throw exception if I do not call .scale(1) and .outputFormat() before calling one of the below function:
Thumbnails.of("source.png").toOutputStream()
Or
Thumbnails.of("source.png").asBufferedImage()
I think .scale(1) should be set as default if user want to process the original one and .outputFormat() can be extracted from file extension.
Hope it's clear now :)
@ntkhanh, the purpose of Thumbnailator is to allow users to simply resize images, so requiring the user to specify call either scale
or size
methods comes from that intended use case. As such, using scale(1.0)
as the default behavior doesn't serve the intended use case well. If you want to do a non-resize operation, you can be explicit by using scale(1.0)
.
As for implicitly calling outputFormat
based on the input format, that's also making assumptions that I'd rather not have Thumbnailator make either. The user should know (and specify) what the output should be.
For those reasons, I'm going to close this issue.
Thumbnails class requires mandatory of scale and outputFormat which is not neccessary when it's possible to set default scale value to 1 (keep original) and outputFormat can be probe from filename.