question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When scaling transparent png images, the colors are being negated.

See original GitHub issue
What steps will reproduce the problem?
1. Scale the attached image and convert to jpeg.
2.
3.

What is the expected output? What do you see instead?
The scaled image is expected in jpeg format.
Getting a scaled jpeg image with negative image color.


What version of the product are you using? On what operating system? Which
version of Java?
Thumbnailator 3.9
Java 1.6.21
Windows 7



Please provide any additional information below.


Original issue reported on code.google.com by rothe...@gmail.com on 22 Sep 2011 at 12:18

Attachments:

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5

github_iconTop GitHub Comments

3reactions
GoogleCodeExportercommented, Jul 25, 2015
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 coobird...@gmail.com on 1 Oct 2011 at 4:57

0reactions
GoogleCodeExportercommented, Jul 25, 2015
Good to hear it worked out. :)

I'll be closing this issue, as it doesn't require any work on Thumbnailator.

Original comment by coobird...@gmail.com on 29 Oct 2011 at 11:02

  • Changed state: Done
  • Added labels: Type-Other
  • Removed labels: Type-Defect
Read more comments on GitHub >

github_iconTop Results From Across the Web

ImageMagick Examples -- Color Modifications
Converting Color to Gray-Scale. Gray scale images can be very useful for many uses, such as, furthering the processing of the original image...
Read more >
Blending modes in Adobe Photoshop
Think in terms of the following colors when visualizing a blending mode's effect: The base color is the original color in the image....
Read more >
12 image formatting mistakes & how to fix them - Canva
Images looking grainy, pixelated or distorted? Learn how to fix your image formatting with this troubleshooting article. We list 12 common mistakes –...
Read more >
How to create an inverted colour (Negative of an image ...
The left image would be the end result of the one on the right. enter image description here. swift · uiimage · colorfilter...
Read more >
Chapter 11: PNG Options and Extensions - libpng.org
But standalone image viewers typically have no preferred background color or ... For grayscale images, with or without alpha, the chunk contains a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found