coobird / thumbnailator

Thumbnailator - a thumbnail generation library for Java
MIT License
5.14k stars 784 forks source link

Option to create thumbnail without extension #150

Closed 4javier closed 2 years ago

4javier commented 4 years ago

Expected behavior

Let the user choose if destination thumbnail name should got an extension or not.

Actual behavior

Extension for output get selected from original image format type if this one doesn't match with the passed extension. (Why??? If it matches, it gets used. If it doesn't matches, it gets used anyway because they're identical. Why not use it directly, ignoring the supplied extension? But that's not the point here...)

Solution

On server, file extensions are quite useless. And they can be tricky to manipulate. I was thinking of a flag NO_EXT to make the system not appending an extension at all to output file. I forked your project and worked out a couple options:

The second one is my favorite approach. Please, tell me what you think about that.

4javier commented 4 years ago

These are the changes I made to add the feature: https://github.com/4javier/thumbnailator/tree/NoExt Give them a look and tell me If you want me to issue a pull request.

Cheers.

jhspetersson commented 3 years ago

+1

Paper-Folding commented 3 years ago

I needs this feature! It is too tried for me to rename files after I have generated thumbnails! Why not the developer merge your pull request???

4javier commented 3 years ago

I didn't actually submit the pull request because I didn't get any response by the author, tbh. Anyway, activity on this repo is kinda low, so I think that the feature is not considered important enough to test it.

Paper-Folding commented 3 years ago

Fine, I should have added your code to the source code in my project, but as I am using maven, I guess I had better add some of code to rename files after thumbnails have generated. However, thanks for you work anyway.

marcioaguiar commented 2 years ago

You can use toOutputStream for that:

try (OutputStream os = new FileOutputStream(new File("myfile"))) {
    Thumbnails.of(input).size(210, 160).toOutputStream(os);
} 
Paper-Folding commented 2 years ago

You can use toOutputStream for that:

try (OutputStream os = new FileOutputStream(new File("myfile"))) {
    Thumbnails.of(input).size(210, 160).toOutputStream(os);
} 

What if I pass in a folder?

coobird commented 2 years ago

This ticket brings up good points, so I'm considering for a later version (such as 0.5.0) where breaking changes wouldn't impact existing consumers of this library.

Superseding with #186.