Comments (5)
Thank you for reporting the issue.
I've tried to resize the provided PNG to a JPEG, but have not been able to
reproduce the color distortion.
My environment is as follows:
* Thumbnailator 0.3.9
* Windows XP
* Java 1.6.0_21
The code that was used was:
Thumbnails.of("images/pic_admin.png")
.size(200, 200)
.outputFormat("jpg")
.toFile("images/Result.jpg");
Could you provide the code used to produce the JPEG with the color distortion?
Thank you!
Original comment by [email protected]
on 23 Sep 2011 at 3:27
from thumbnailator.
I'm not using the from file to file method, but taking a byte array and
returning one.
InputStream inputStream = new ByteArrayInputStream(imageByteArray);
final BufferedImage bufferedImage =
Thumbnails.of(inputStream).outputFormat("jpg").size(200, 200).asBufferedImage();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
imageIO.write(bufferedImage, "jpg", outputStream);
return outputStream.toByteArray();
Original comment by [email protected]
on 26 Sep 2011 at 8:30
from thumbnailator.
Thank you for the follow up.
I was able to get an image with color distortion using the following, based on
the information I got from your code:
--------------------
BufferedImage bufferedImage =
Thumbnails.of(new FileInputStream("images/pic_admin.png"))
.outputFormat("jpg")
.size(200, 200)
.asBufferedImage();
ImageIO.write(bufferedImage, "jpg", new FileOutputStream("images/Result.jpg"));
--------------------
It appears that the issue here is that you're using the `ImageIO.write` method
to write the `BufferedImage` to the `ByteArrayOutputStream`.
It turns out, the JPEG codec that is provided with Image I/O will create JPEG
images with transparency, but many applications will not recognize the
transparency and will display with distorted colors. (The image with the
transparency that is provided to the codec in this case is the `BufferedImage`
from Thumbnailator.)
(If you're interested, refer to the following link for more information:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4836466)
To get around this problem, Thumbnailator internally removes the transparency
before saving the image to a JPEG, which avoids the color distortion issue.
So, this is not quite an issue with Thumbnailator, but an issue with how the
`ImageIO` class is being used.
--------------------
The following code should create an image which will not exhibit the color
distortion problem:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Thumbnails.of(new ByteArrayInputStream(imageByteArray))
.outputFormat("jpg")
.size(200, 200)
.toOutputStream(outputStream);
return baos.toByteArray();
Please let me know if that will solve the issue.
Original comment by [email protected]
on 1 Oct 2011 at 4:57
from thumbnailator.
Solved the issue!
Thanks :)
Original comment by [email protected]
on 27 Oct 2011 at 11:26
from thumbnailator.
Good to hear it worked out. :)
I'll be closing this issue, as it doesn't require any work on Thumbnailator.
Original comment by [email protected]
on 29 Oct 2011 at 11:02
- Changed state: Done
- Added labels: Type-Other
- Removed labels: Type-Defect
from thumbnailator.
Related Issues (20)
- Watermark position incorrect for images re-oriented using EXIF metadata HOT 3
- Move to GitHub (and transition to a Git repository) HOT 5
- Change build from Ant to Maven HOT 4
- Google Project Hosting will drop support for Downloads HOT 3
- Using JAI library? HOT 1
- Thumbnailing problem for a specific JPEG image HOT 1
- OutOfMemoryError: Java heap space / Builder.asBufferedImage HOT 3
- Exception on opening nested folder HOT 5
- Recursively process images in nested directories
- Low quality when resizing a GIF image HOT 2
- Unexpected behaviour when using toFile without an extension matching output format HOT 1
- Support animated GIFs HOT 2
- Javadoc on Thumbnailator class has unclear remark on OutOfMemoryError HOT 3
- Implement a workaround for common OutOfMemoryError cases HOT 15
- java.lang.OutOfMemoryError: Java heap space after adding thumbnailator-feature-oom-workaround-SNAPSHOT.jar file HOT 6
- Please retain debug information in published JAR HOT 3
- forceSize Not maintaining the Aspect Ratio of thr original image HOT 5
- "Image cannot be null" when using `Thumbnails.of(BufferedImage...)` HOT 2
- Use embedded thumbnail from large JPEG images HOT 1
- SVG not supported
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from thumbnailator.