GithubHelp home page GithubHelp logo

Comments (5)

GoogleCodeExporter avatar GoogleCodeExporter commented on May 21, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 21, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 21, 2024
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.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 21, 2024
Solved the issue!
Thanks :)

Original comment by [email protected] on 27 Oct 2011 at 11:26

from thumbnailator.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 21, 2024
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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.