Closed javaofferss closed 2 years ago
file type is svg
Thumbnailator is a library that works on top of the Java Image I/O API. Since Java by default does not support SVGs, you'll need to use a third-party image reader/writer for SVG to open them.
For more information, please refer to the FAQ. (TwelveMonkeys ImageIO appears to have support for SVGs.)
I'm having this same issue with PNG files. Something seems to have changed as this library worked fine for PNG files for a long while
Hello @goodale, could you provide a bit more detail on what you're having issues with? Which version of Thumbnailator and Java are you using? Also a snippet of how Thumbnailator is being used would be nice to know. (Especially what type of input, like InputStream
or File
, and what kind of output as well.)
For security best practices I was trying to use Java's tempfile utility class. The issue appears to be related to that. After i reverted my code to use a standard file it worked ok
This code failed: public static void resize(FileItem fi, String fileName) { File tmpFile= File.createTempFile("tmp","png"); Thumbnails.of(fi.getInputStream()).size(327, 36).addFilter(new Canvas(66, 36, Positions.TOP_RIGHT, true)).toFile(tmpFile); InputStream is = new FileInputStream(tmpFile); ... }
This code works: public static void resize(FileItem fi, String fileName) { File tmpFile= new File("tmp.png"); Thumbnails.of(fi.getInputStream()).size(327, 36).addFilter(new Canvas(66, 36, Positions.TOP_RIGHT, true)).toFile(tmpFile); InputStream is = new FileInputStream(tmpFile); ... }
On Wed, Feb 9, 2022 at 6:42 AM Chris Kroells @.***> wrote:
Hello @goodale https://github.com/goodale, could you provide a bit more detail on what you're having issues with? Which version of Thumbnailator and Java are you using? Also a snippet of how Thumbnailator is being used would be nice to know. (Especially what type of input, like InputStream or File, and what kind of output as well.)
— Reply to this email directly, view it on GitHub https://github.com/coobird/thumbnailator/issues/184#issuecomment-1033670743, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJDHB3MCPW425ZQYZHG32LU2JHI3ANCNFSM5MGRJWZA . You are receiving this because you were mentioned.Message ID: @.***>
@goodale The indicated changes on shouldn't be the cause for a "No suitable ImageReader found for source data" error because your changes are only on the output side of things.
One thing that will affect the behavior is the latter one provides a hint to Thumbnailator to save as a PNG because you're using a .png
extension, while the former example doesn't. (It adds a png
suffix to the file name, but is not an "extension" like .png
, so the file names are probably something like "tmp123456png")
If you'd like to use the temporary file approach, you could set the suffix to ".png" by calling it like File.createTempFile("tmp", ".png")
or you could tell Thumbnailator to output in PNG format by calling outputFormat("png")
.
Thanks for the quick reply. I thought I was already setting the 'png' extension when i tried to create the temp file, but that didn't work.
File tmpFile= File.createTempFile("tmp","png"); Thumbnails.of(fi.getInputStream()).size(327, 36).addFilter(new Canvas(66, 36, Positions.TOP_RIGHT, true)).toFile(tmpFile); InputStream is = new FileInputStream(tmpFile);
I'll try your outputFormat("png") https://coobird.github.io/thumbnailator/javadoc/0.4.16/net/coobird/thumbnailator/Thumbnails.Builder.html#outputFormat(java.lang.String). suggestion
Thanks, Steve
On Wed, Feb 9, 2022 at 12:34 PM Chris Kroells @.***> wrote:
@goodale https://github.com/goodale The indicated changes on shouldn't be the cause for a "No suitable ImageReader found for source data" error because your changes are only on the output side of things.
One thing that will affect the behavior is the latter one provides a hint to Thumbnailator to save as a PNG because you're using a .png extension, while the former example doesn't. (It adds a png suffix to the file name, but is not an "extension" like .png, so the file names are probably something like "tmp123456png")
If you'd like to use the temporary file approach, you could set the suffix to ".png" by calling it like File.createTempFile("tmp", ".png") or you could tell Thumbnailator to output in PNG format by calling outputFormat("png") https://coobird.github.io/thumbnailator/javadoc/0.4.16/net/coobird/thumbnailator/Thumbnails.Builder.html#outputFormat(java.lang.String) .
— Reply to this email directly, view it on GitHub https://github.com/coobird/thumbnailator/issues/184#issuecomment-1034019695, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJDHB5ZFSVRL6NMV236ML3U2KQRLANCNFSM5MGRJWZA . You are receiving this because you were mentioned.Message ID: @.***>
I am using the latest version but where i'm making a mistake any idea i want to create a thumbnail of an HTML page which is in the htmlContent string?
Document doc = Jsoup.parse(htmlContent);
final ByteArrayInputStream inputStream = new ByteArrayInputStream(doc.toString().getBytes());
Thumbnails.of(inputStream).size(WIDTH, HEIGHT).outputFormat("png").toFile(new File("thumbnail.png"));
The exception stacktrace is: net.coobird.thumbnailator.tasks.UnsupportedFormatException: No suitable ImageReader found for source data. at net.coobird.thumbnailator.tasks.io.InputStreamImageSource.read(Unknown Source) at net.coobird.thumbnailator.tasks.SourceSinkThumbnailTask.read(Unknown Source) at net.coobird.thumbnailator.Thumbnailator.createThumbnail(Unknown Source) at net.coobird.thumbnailator.Thumbnails$Builder.toFile(Unknown Source)
Thanks,
@ameekkhan, Thumbnailator is a library that makes thumbnails of image files such as JPEG and PNG.
HTML is text, so there is no way for Thumbnailator to make a thumbnail out of that. If you need to make a thumbnail of a website, you'll need to render that website as an image first, which is outside the scope of the Thumbnailator project.
@coobird thanks!
I'll be locking conversations on this issue, as the original issue is already closed.
For those of you who found this issue with "No suitable ImageReader found for source data" exception message, please first check other issues to see if they're applicable to you, and if not, feel free to open another issue.
Expected behavior
net.coobird.thumbnailator.tasks.UnsupportedFormatException: No suitable ImageReader found for source data. at net.coobird.thumbnailator.tasks.io.InputStreamImageSource.read(Unknown Source) at net.coobird.thumbnailator.tasks.SourceSinkThumbnailTask.read(Unknown Source) at net.coobird.thumbnailator.Thumbnailator.createThumbnail(Unknown Source) at net.coobird.thumbnailator.Thumbnails$Builder.toFile(Unknown Source) at com.mh.others.tool.pictrue.ImageCompressUtil.compressImage(ImageCompressUtil.java:51)
my code: FileInputStream fileInputStream = new FileInputStream(file); Thumbnails.of(fileInputStream) .scale(1f) .outputQuality(quality) .toFile(destFileUrl);
Actual behavior
Please describe the actual behavior you are experiencing, including stack trace and other information which would help diagnose the issue.
Steps to reproduce the behavior
Please enter step-by-step instructions for reproducing the actual behavior. Including code can be helpful in diagnosing issue, but please keep the code to a minimal that will reproduce the behavior.
Environment
Please provide vendor and version information for the Operating System, JDK, and Thumbnailator. Please feel free to add any other information which may be pertinent.