linpeixun / thumbnailator

Automatically exported from code.google.com/p/thumbnailator
Other
0 stars 0 forks source link

Unexpected behaviour when using toFile without an extension matching output format #66

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Take this small code block:

File inputFile = new File("...");
File outputFile = File.createTempFile("thumbnail", null);
Thumbnails.of(inputFile).size(100,100).outputFormat("jpg").toFile(outputFile);

My expected result is that outputFile contains the thumbnail, which I think is 
reasonable and in line with the javadocs of toFile. However, Thumbnailator 
writes the thumbnail to a new file with .jpg appended, which isn't exposed 
anywhere, so my code in principle has no way of accessing the thumbnail without 
knowledge of the internal implementation.

Obviously this is easy enough to work around by creating the temp file with a 
.jpg extension, but this really shouldn't be needed.

Original issue reported on code.google.com by bjmac...@gmail.com on 19 Feb 2014 at 8:15

GoogleCodeExporter commented 9 years ago
Thank you for the detailed report.

Your use case was definitely something that was overlooked.

The current Thumbnailator, with regard to file output, will try to append a 
"correct" extension to the file name if one is not present. And yes, you're 
correct in that is it not documented.

The only certain way to currently workaround this issue is to use a 
`FileOutputStream` to write the thumbnail -- using a `OutputStream` prevents 
Thumbnailator from changing the destination file:

  FileOutputStream os = new FileOutputStream("thumbnail");

  Thumbnails.of(inputFile)
    .size(100, 100)
    .outputFormat("jpg")
    .toOutputStream(outputStream);

  os.close();

This behavior should be (a) possible to be disabled or (b) at least documented, 
so I will accept this issue as something that needs attention.

Another solution would be to add a `asFile` method that will return a `File` 
object to the resulting thumbnail -- that should address the issue of having 
"no way of accessing the thumbnail".

Once again, thank you for taking time to report this issue.

Original comment by coobird...@gmail.com on 23 Feb 2014 at 9:27

GoogleCodeExporter commented 9 years ago
The Thumbnailator project will move to GitHub due to the Google Project Hosting 
going read-only in one month.
http://google-opensource.blogspot.jp/2015/03/farewell-to-google-code.html

This issue has been migrated to GitHub at the following URL:
https://github.com/coobird/thumbnailator/issues/66

Original comment by coobird...@gmail.com on 25 Jul 2015 at 10:53