Skip to content
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

Option to create thumbnail without extension #150

Closed
4javier opened this issue Mar 31, 2020 · 8 comments
Closed

Option to create thumbnail without extension #150

4javier opened this issue Mar 31, 2020 · 8 comments

Comments

@4javier
Copy link

4javier commented Mar 31, 2020

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:

  • Simpler dirty one:
    add a new const NO_EXT to Rename class, that strips out the extension from the file.
    Drawback is that all the work done by FileImageSink to appending it, would be wasted.
  • Correct heavy one:
    adding NO_EXT as Builder property (I got to study a bit this part of your code. It's kinda obscure to me...), and check for its value in FileImageSinkValue.write(BufferedImage) before all the other ones already present, and if true calling simply new File(destinationFile.getAbsolutePath())

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

@4javier
Copy link
Author

4javier commented Apr 1, 2020

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
Copy link

+1

@Paper-Folding
Copy link

Paper-Folding commented Aug 14, 2021

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
Copy link
Author

4javier commented Aug 15, 2021

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
Copy link

Paper-Folding commented Aug 16, 2021

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
Copy link

You can use toOutputStream for that:

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

@Paper-Folding
Copy link

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
Copy link
Owner

coobird commented Feb 11, 2022

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.

@coobird coobird closed this as completed Feb 11, 2022
PENEKhun added a commit to a-na-ba-da/backend that referenced this issue Jul 10, 2023
기존 Thumbnail 라이브러리에서 썸네일을 생성할때, 확장자가 없어도 자동으로 생성하는지 몰랐었네요.
reference issue : coobird/thumbnailator#150
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants