Adding jpeg thumbnail
Added by Mike Erickson about 6 years ago
Is there something I'm missing when adding a jpeg preview thumbnail to an image that doesn't have one already? I have a buffer that contains a properly compressed and formatted jpeg image without any metadata. I want to add it as a preview to another jpeg. I add it thusly to the Exiv2::Image auto pointer:
Exiv2::ExifThumb exifThumb( exiv_meta_image->exifData() );
exifThumb.setJpegThumbnail( buffer, size, std::make_pair( 96, 1 ), std::make_pair( 96, 1 ), 2/*RESUNIT_INCH in tiff.h*/ );
I write the metadata out to the main jpeg file. All my other metadata changes are there, but no EXIF thumnbnail is present. What am I doing wrong?
Replies (5)
RE: Adding jpeg thumbnail - Added by Robin Mills about 6 years ago
Mike. Good to hear from you. I hope you're well.
I don't know the answer to your question and don't have time today to investigate this. However, I'll give you the recipe to find the solution. Let me explain the exiv2 commands to insert a preview into an image and you can step the code in the debugger to discover how we achieve this. Then you'll probably be able to answer your own question.
1 I'm using a photo I took at Stonehenge in July and using the wiz-bang 'webready' feature to extract its preview over http
792 rmills@rmillsmbp:~/gnu/exiv2/trunk $ exiv2 -pp http://dev.exiv2.org/attachments/download/805/DSC_7154.jpg Preview 1: image/jpeg, 160x120 pixels, 10837 bytes 793 rmills@rmillsmbp:~/gnu/exiv2/trunk $ exiv2 -ep http://dev.exiv2.org/attachments/download/805/DSC_7154.jpg 794 rmills@rmillsmbp:~/gnu/exiv2/trunk $ ls -alt *.jpg -rw-r--r--+ 1 rmills staff 10837 25 Sep 13:40 DSC_7154-preview1.jpg 795 rmills@rmillsmbp:~/gnu/exiv2/trunk $2 Copy a test file (any jpg is fine) and list the previews:
795 rmills@rmillsmbp:~/gnu/exiv2/trunk $ cp test/data/exiv2-bug884c.jpg . 796 rmills@rmillsmbp:~/gnu/exiv2/trunk $ exiv2 -pp exiv2-bug884c.jpg Preview 1: image/jpeg, 640x480 pixels, 38828 bytes 797 rmills@rmillsmbp:~/gnu/exiv2/trunk $3 Rename the Stonehenge preview (DSC_7154-preview1.jpg) as exiv2-bug884c-thumb.jpg and insert it into exiv2-bug884c.jpg
797 rmills@rmillsmbp:~/gnu/exiv2/trunk $ mv DSC_7154-preview1.jpg exiv2-bug884c-thumb.jpg 798 rmills@rmillsmbp:~/gnu/exiv2/trunk $ exiv2 -it exiv2-bug884c.jpg4 Success: you can see there's a new preview of 10837 bytes!
799 rmills@rmillsmbp:~/gnu/exiv2/trunk $ exiv2 -pp exiv2-bug884c.jpg Preview 1: image/jpeg, 160x120 pixels, 10837 bytes Preview 2: image/jpeg, 640x480 pixels, 38828 bytes 800 rmills@rmillsmbp:~/gnu/exiv2/trunk $You can run the command exiv2 -it exiv2-bug884c.jpg in the debugger. Set a break-point at Insert::insertThumbnail() in actions.cpp
And the bill for my help is: Please report your solution back here to help another user.
RE: Adding jpeg thumbnail - Added by Mike Erickson about 6 years ago
Strangely, my code as it exists works when writing a thumbnail to a TIFF file, but not to a jpeg.
RE: Adding jpeg thumbnail - Added by Robin Mills about 6 years ago
Andreas wrote the code, so he may be able to explain this. This is a nice little puzzle for you to end the week on a high-note. Have a little step with the debugger and find the difference.
RE: Adding jpeg thumbnail - Added by Mike Erickson about 6 years ago
Any tips? This seems broken or difficult to use. Even when I get the tiff written out and containing a thumbnail, the thumbnail appears stretched and mis-sized. I can verify my jpeg encoding is correct by sticking the buffer in a file on disk and opening it successfully with a variety of editors.
The main jpeg file never seems to contain the thumbnail when I add it the way that I am.
RE: Adding jpeg thumbnail - Added by Robin Mills about 6 years ago
Mike
I was going to suggest sticking the data into a file to verify that the data is good. However I see you've thought of that. Here are a couple of extra steps you can try.
1) Use exiv2(.exe) -it to insert the thumbnail. If exiv2 does it right, you can only be a few steps in the debugger from fixing this.
You need to give the thumb image the name foo-thumb.jpg for the file foo.jpg and (I'm guessing) foo-thumb.tif for foo.tif
2) If exiv2 also gets it wrong, can you dump the structure of your thumb name exiv2 -pS foo-thumb.tif
I spotted a comment in the code about ensuring there is no metadata in the thumbnail. Yes, I know you said you had deleted all metadata from foo-thumb.tif - however try this to be certain.
3) If you're still stuck, please post your image and your thumb image and I'll look at it for you. It's 9pm (3pm CST) in England now. I'll be around until about 10pm (4pm CST).
Can you drop me an email if you're stuck as I didn't get a notification from Redmine. I only found your request because I inspected Redmine and was thinking about packing it in for the day: robin@clanmills.com
Robin