Closed GoogleCodeExporter closed 9 years ago
Hi there,
I'm going to need more information to find out what is going on:
1. What is the value of `originalImage`? What is actual file name?
2. What is `File originalImage` pointing to? A JPEG image? A PNG image?
Something else?
3. Are they both created from the same image file?
4. Are you running the two lines of code one after another?
One thing I did notice about the code is that the source image file and the
destination image file is the same `File` (or `String`) so I believe that the
thumbnail is overwriting the original image.
(That might be what you're intending, but I just wanted to double-check.)
Original comment by coobird...@gmail.com
on 28 Jun 2011 at 2:47
Thank you! I found the problem. Exactly as you said, it's because the source
image file and the destination image file is the same File.
The following code works perfect:
BufferedImage image = ImageIO.read(new File("test.jpg"));
Thumbnails.of(image).size(600, 800).toFile(new File("bigPreview.jpg"));
After compressed, the size of "bigPreview.jpg" is only 80KB.
If the destination file and the source file is the same file:
BufferedImage image = ImageIO.read(new File("test.jpg"));
Thumbnails.of(image).size(600, 800).toFile(new File("test.jpg"));
Although its resolution changed, its size doesn't change.
Original comment by moshangc...@gmail.com
on 29 Jun 2011 at 3:29
Thank you for the follow up.
I was able to reproduce your issue for JPEG and PNG images:
Thumbnails.of("path/to/png")
.size(100,100)
.toFile("path/to/png");
Thumbnails.of("path/to/jpg")
.size(100,100)
.toFile("path/to/jpg");
(Reproduced on JRE 6, Windows XP, Thumbnailator 0.3.5)
It does seem odd that the file size remains the even when the image has changed.
I'll take a closer look at this issue in the next few days.
Original comment by coobird...@gmail.com
on 29 Jun 2011 at 3:56
This issue definitely seems to be a defect.
The following two examples should be (more or less) equivalent:
Example 1
-----------
Thumbnails.of("path/to/png")
.size(100,100)
.toFile("path/to/png");
Example 2
-----------
BufferedImage img = Thumbnails.of("path/to/png")
.size(100,100)
.asBufferedImage();
ImageIO.write(img, "png", new File("path/to/png"));
However, in (1) the file size of `path/to/png` before and after the resize
operation does not change.
Original comment by coobird...@gmail.com
on 9 Jul 2011 at 7:47
This issue has been addressed, and will be part of the Thumbnailator 0.3.6
release.
------
This issue was occurring due to the way the `ImageOutputStream` returned by
Image I/O was writing data to the beginning of the destination file, if the
destination file already exists.
The code in question was:
ImageOutputStream ios = ImageIO.createImageOutputStream(destinationFile);
A workaround was to hand over a `FileOutputStream` to the
`ImageIO.createImageOutputStream` method when obtaining an `ImageOutputStream`.
I'll close this issue once Thumbnailator 0.3.6 is released.
Original comment by coobird...@gmail.com
on 9 Jul 2011 at 11:29
A fix for this issue was released as part of Thumbnailator 0.3.6.
Original comment by coobird...@gmail.com
on 9 Jul 2011 at 3:01
Original issue reported on code.google.com by
moshangc...@gmail.com
on 28 Jun 2011 at 6:23