4

In a Chrome App (packaged app), I have FileEntry objects that represent JPEG images, and I'd like to show them as thumbnails. However, it seems that the only way to access the image data is in its entirety, with the FileEntry.file method, which produces a File (subclass of Blob). As some of the images are >4MB, this is way too inefficient for showing, say, 50 thumbnails in the window.

Am I correct that there is no API for accessing just the thumbnail, or is there some HTML5 or Chrome API that I'm missing?

[Clarification: When I say "extract thumbnail", I mean reading just the thumbnail data, which is inside nearly all JPEGs. I don't mean extracting the primary compressed JPEG data and showing it thumbnail size, nor do I mean reading the binary data and pulling out the part that represents the thumbnail, as that still means reading into memory the whole file.]

Marc Rochkind
  • 3,678
  • 3
  • 30
  • 38
  • possible duplicate of [Extract thumbnail from jpeg file](http://stackoverflow.com/questions/10349622/extract-thumbnail-from-jpeg-file) – sowbug Apr 06 '14 at 15:20
  • Indeed, it is. I was not aware that I can take a slice of the File object without incurring the overhead of reading the whole file. Thanks! (I'm not sure this is documented anywhere.) – Marc Rochkind Apr 17 '14 at 17:30

2 Answers2

0

As a general proposition, it is possible to read the thumbnail without decompressing the image.

The location of the Thumbnail depends upon the specific JPEG file format used. JPEG itself, does not define thumbnails.

That said, my experience is that very few JPEG files actually contain thumbnails.

I would check the file format headers (e.g., EXIF, JPEG) to see if there actually are thumbnails in your images.

You may have to extract the thumbnails yourself from the headers display them. In JFIF, the thumbnail may either be uncompressed or it may be a nested JFIF stream.

user3344003
  • 20,574
  • 3
  • 26
  • 62
  • 1
    I'm not asking how to locate the thumbnail. I'm asking how to get at it in JavaScript without bringing the entire file into memory. To read in >4MB to get at a tiny thumbnail is much too inefficient. (Did you see my "Clarification" paragraph?) – Marc Rochkind Apr 05 '14 at 22:20
  • 2
    There are several near-duplicate questions on Stack Overflow that already have answers, such as http://stackoverflow.com/a/16130081/344467. The existence of those questions, and the sample code accompanying the answers, suggests that there is no thumbnail API (and for various reasons it wouldn't be a very popular feature at a platform level). – sowbug Apr 06 '14 at 15:23
  • That API is for accessing a JPEG with native code, which is theoretically possible from a Chrome App. I should perhaps have made it more clear that I was asking about working from FileEntry objects, as stated in the first sentence of my question, above, and using an API that can be accessed directly (in JavaScript) from the Chrome App code. – Marc Rochkind Apr 14 '14 at 17:50
0

Comment from sowbug to my OP is the answer I was looking for.

Marc Rochkind
  • 3,678
  • 3
  • 30
  • 38