thumbnailator
thumbnailator copied to clipboard
Handle large image files in an memory-efficient manner
Problem
-------
* Currently, Thumbnailator does not have good support for large image files.
For example, there is no protection against running out of memory, and this
behavior is completely dependent upon the JVM's memory settings.
Solution
--------
* Support tiled reading of image files, rather than reading the entire files at
once, as is implemented currently.
Complications
-------------
* Changes to support reading images by tiles will most likely lead to changes
to the API.
Original issue reported on code.google.com by [email protected]
on 22 Sep 2010 at 4:28
The most likely place to add support for this feature is the `ThumbnailTask`
interface.
The `read` method (and possibly `write` method) would be changed to return
image tiles, rather than a single `BufferedImage`.
This change would affect a fairly significant portion of Thumbnailator.
This feature is not expected to be in the Thumbnailator 0.3.0 release.
Original comment by [email protected]
on 23 Dec 2010 at 4:53
- Changed state: Accepted
Original comment by [email protected]
on 11 Feb 2012 at 7:17
- Changed title: Handle large image files in an memory-efficient manner
Original comment by [email protected]
on 26 Feb 2012 at 6:25
- Added labels: Priority-Low
- Removed labels: Priority-Medium
I don't think this issue has a priority Low. I got a lot of
OutOfMemoryException when processing large images and so i can't use this lib.
This is a shame because I found your library very well shaped in term of usage.
Do you think you can move on ?
Original comment by [email protected]
on 21 Sep 2012 at 8:25
It's interesting that this issue was brought up again, as I've actually been
seriously considering putting this issue at a higher priority -- I've also
noticed some blog postings where people were encountering `OutOfMemoryError`s,
so I suspect there are quite a few people out there who are having the same
problem.
In the past week, I have started experimenting with an approach to reduce
memory usage.
(It's a different approach from the idea I had two years ago, but it will
require a little bit of rework, but very unlikely to cause any problems with
existing code.)
I can't make any promises, but hopefully I will be able to address this issue
in a not-so-distant release.
Original comment by [email protected]
on 23 Sep 2012 at 3:02
- Added labels: Priority-Medium
- Removed labels: Priority-Low
I managed to fix my issue by increasing the JVM memory (-Xms512m -Xmx512m).
I didn't try with very large image (50k x 50k for instance) but Thumbnailator
works very well with standard image size (less than 10mo) if you increase the
JVM memory.
Thanks for your work on this project, Thumbnailator is great.
Original comment by [email protected]
on 24 Sep 2012 at 8:07
There seems to be issues with Java 7 Update 21 causing `OutOfMemoryError`s more
frequently than previous versions/updates of Java.
Java 7 Update 21 is the current version of Java at this point in time.
I may need to look into increasing the priority of this issue.
Original comment by [email protected]
on 12 May 2013 at 3:00
The `OutOfMemoryError` issue with Java 7 Update 21 was a separate, *unrelated*
issue that was caused by the incorrect handling of resources (not disposing
`ImageReader`s and `ImageWriter`s after using it) which lead to some kind of
memory leak.
That `OutOfMemoryError` issue has been fixed in Issue 42 and released as part
of Thumbnailator 0.4.4.
----
Issue 1 will be tackling the issue of dealing with how to reduce the amount of
memory being used when the thumbnail image is being generated.
Original comment by [email protected]
on 2 Jun 2013 at 12:12
[deleted comment]
Hi,
I am encountering this issue even with the latest Thumbnailator-0.4.7-all.jar
Here is the exception that I get
java.lang.OutOfMemoryError: Java heap space
at java.awt.image.DataBufferByte.<init>(DataBufferByte.java:42)
at java.awt.image.Raster.createInterleavedRaster(Raster.java:253)
at java.awt.image.BufferedImage.<init>(BufferedImage.java:365)
at net.coobird.thumbnailator.resizers.ProgressiveBilinearResizer.resize(Unknown Source)
at net.coobird.thumbnailator.resizers.Resizers.resize(Unknown Source)
at net.coobird.thumbnailator.makers.ThumbnailMaker.makeThumbnail(Unknown Source)
at net.coobird.thumbnailator.makers.FixedSizeThumbnailMaker.make(Unknown Source)
at net.coobird.thumbnailator.Thumbnailator.createThumbnail(Unknown Source)
Do you have any plans to address this issue?
Thanks
Original comment by [email protected]
on 29 Apr 2014 at 11:23
Wow! That's the same issue I just encountered.
java.lang.OutOfMemoryError: Java heap space
at java.awt.image.DataBufferByte.<init>(DataBufferByte.java:42)
at java.awt.image.Raster.createInterleavedRaster(Raster.java:253)
at java.awt.image.BufferedImage.<init>(BufferedImage.java:365)
Iam using net.coobird 0.4.7 as well. Hope someone can solve this problem.
Original comment by [email protected]
on 29 Apr 2014 at 3:08
I am glad I am not the only with this issue :).
Original comment by [email protected]
on 29 Apr 2014 at 4:52
I'm considering creating a temporary workaround (which should work
transparently without user intervention) that should prevent most of the
`OutOfMemoryError`s that I believe users are experiencing.
The temporary workaround will be implemented as described in Issue 69.
Original comment by [email protected]
on 4 May 2014 at 5:39
Sometimes it also happens when reading the image:
java.lang.OutOfMemoryError: Java heap space
at java.awt.image.DataBufferByte.<init>(DataBufferByte.java:58)
at java.awt.image.ComponentSampleModel.createDataBuffer(ComponentSampleModel.java:397)
at java.awt.image.Raster.createWritableRaster(Raster.java:938)
at javax.imageio.ImageTypeSpecifier.createBufferedImage(ImageTypeSpecifier.java:1056)
at javax.imageio.ImageReader.getDestination(ImageReader.java:2879)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:943)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:915)
at javax.imageio.ImageReader.read(ImageReader.java:923)
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)
Original comment by [email protected]
on 5 May 2014 at 5:27
Any news
Dear Chris/ @coobird . I suppose you (like myself) have little time for unpaid projects. Nonetheless, I cross my fingers and hope for some good news that somehow there will be progress on this issue soon. Any updates? Best Regards, Sean
@coobird would you be interested in trying an ImageProducer/ImageConsumer based approach to this problem? I have working code that does this, but I'd take me some time to make a PR for this project.
This solution has worked for me for years, but, well, it's complicated. It may still be appropriate to implement a tile-based fallback if the ImageProducer doesn't receive the pixels in the order it needs. (And using java.awt.Images
instead of BufferedImages
means we're focusing mostly on PNGs and JPGs.)