Project

General

Profile

Thumbnail is not the exact reduced copy of Image

Added by Paul Mybofy about 6 years ago

Bonjour

I extract a buffer containing a JPEG image from a postgresql database :

            binarystring binStr(cursor0[1]); // from pqxx
            const unsigned char *buffer = (unsigned char *)binStr.get();
            Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open((Exiv2::byte *)buffer, binStr.length());

I can write image to a file :

            Exiv2::FileIo file0("/Users/.../Tmp/toto.jpeg");
            int sts = file0.open("w");
           file0.write(image->io());

That is OK !

I extract the thumbnail from image :

            image->readMetadata();
            Exiv2::ExifData &exifData = image->exifData();
            if (exifData.empty()) { cout << "exifData.empty()" << endl; }
            Exiv2::ExifThumb *thumbnail = new Exiv2::ExifThumb(exifData);

I can write thumbnail to a file:

            thumbnail->writeFile("/Users/.../Tmp/toto"); // OK !!! .jpg ajouté automatiquement

That is almost OK...

There is black bands at the top and bottom of the thumbail image.
The same appends when I write the thumbail to memory buffer and show the image on the screen...

I suppose there is a problem of size(height) of thumbnail vs size(height) of image, but I do not see how to proced to correct the problem.

Thanks for the help.

Sorry for my English.

tata.jpg (12.8 KB) tata.jpg

Replies (2)

RE: Thumbnail is not the exact reduced copy of Image - Added by Robin Mills about 6 years ago

Your English is fine. I recently discussed reading and writing previews with Mike Ericsson: http://dev.exiv2.org/boards/3/topics/2250

I think this has something to do with the aspect ratio of your image and preview being different. Here's a photo I took at Stonehenge in July. My Nikon D5300 takes images at 6000x4000 (3/2) and the Preview is 160x120 (4/3). The preview has horizontal bars.

547 rmills@rmillsmbp:~/gnu/exiv2/trunk $ exiv2 -pa --grep Dimension http://dev.exiv2.org/attachments/download/805/DSC_7154.jpg 
Exif.Photo.PixelXDimension                   Short       1  6000
Exif.Photo.PixelYDimension                   Short       1  4000
548 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
549 rmills@rmillsmbp:~/gnu/exiv2/trunk $ exiv2 -ep --force http://dev.exiv2.org/attachments/download/805/DSC_7154.jpg 
550 rmills@rmillsmbp:~/gnu/exiv2/trunk $ exiv2 DSC_7154-preview1.jpg  2>/dev/null
File name       : DSC_7154-preview1.jpg
File size       : 10837 Bytes
MIME type       : image/jpeg
Image size      : 160 x 120
551 rmills@rmillsmbp:~/gnu/exiv2/trunk $ 
It looks as though my Nikon scales the image from 6000x4000 (3/2) to 160x106 (3/2). Then he add 2 'bars' of 7 black pixels to achieve a preview 160x120 (4/3). Perhaps the Exif standard requires the preview to be 4/3. I can't see this defined, however the example is 80x60. http://www.cipa.jp/std/documents/e/DC-008-2012_E.pdf

[Résolu] RE: Thumbnail is not the exact reduced copy of Image - Added by Paul Mybofy about 6 years ago

"It looks as though my Nikon scales the image from 6000x4000 (3/2) to 160x106 (3/2). Then he add 2 'bars' of 7 black pixels to achieve a preview 160x120 (4/3). Perhaps the Exif standard requires the preview to be 4/3. I can't see this defined, however the example is 80x60. http://www.cipa.jp/std/documents/e/DC-008-2012_E.pdf"

The same for my Sony X100.
I use wxWidgets which has the class wxImage :

wxImage     Size (const wxSize &size, const wxPoint &pos, int red=-1, int green=-1, int blue=-1) const
     Returns a resized version of this image without scaling it by adding either a border with the given colour or cropping as necessary. More...

Doing :

 wxImage sizedThumb = imgThumb.Size(wxSize(160, 106), wxPoint(0, -7));

works fine.

Grand merci pour l'aide.

    (1-2/2)