[XeTeX] jpg image and text overlapping
Heiko Oberdiek
heiko.oberdiek at googlemail.com
Mon Aug 4 21:53:17 CEST 2014
On 04.08.2014 19:50, Stefan Solbrig wrote:
>> Turns out we've also been bit by this problem... please see my
>> questions below.
>>
>> On 2014-08-04 01:55, Heiko Oberdiek wrote:
>>> On 04.08.2014 01:27, Gildas Hamel wrote:
>>>> I append the jpg file (tombe.jpg).
>>> The resolution data in tombe.jpg are inconsistent:
>>> * JFIF header: 72 DPI
>>> * EXIF header: 300 DPI
>>
>> What program did you use to determine this?
Hex editor. Most image programs are quite useless for this problem,
because they do not tell, which resolution data they are using.
I'm looking at one of our
>> jpgs in a text editor, and while I see the string "Exif" near the top,
>> I don't see any jfif-like string.
You can find 'JFIF' of tombe.jpg at position 6, meaning, there are
six other bytes before the string.
> GIMP reports 72x72 ppi, but I don't
>> know whether that's exif or jfif.
Apparently JFIF.
>>> Apparently XeTeX uses the EXIF header, whereas xdvipdfmx the JFIF header
>>> (or vice versa).
>>
>> Is there a work-around?
Fixing the resolution data.
* Manual way with hex editor: Putting bytes 0x1 0x2C 0x1 0x2C
at position 14 in tombe.jpg replacing bytes 0x00 0x48 0x00 0x48.
Then the image has 300 DPI
* Removing the EXIF header:
jpegtran -copy none -outfile tombe2.jpg tombe.jpg
This strips all extra stuff including EXIF from the JPEG
file.
>> Like using some image editor to produce a jpg
>> file with jfif and exif headers that agree on the resolution (and I
>> suppose have the correct one :-)), or maybe converting from jpg to
>> some other format?
Image editor and other format are problematic, because JPEG is a lossy
format and decoding/encoding steps would decrease the quality unnecessary.
> I suppose I could create a PDF using pdflatex, and
>> import that into my xetex file instead of the original jpg.
Also possible, then XeTeX/xdvipdfmx will use the dimensions
of the PDF file. The price is a little overhead of the PDF wrapper.
> There is a tool named "exiftool" that can do this. It modifies image
> metadata without changing the image itself. You can install it either
> via a package manger (in Debian it's "libimage-exiftool-perl") or you
> can install it via CPAN (the perl package manager, because it it part of
> a perl package. If you use cpan, do:
> cpan
> cpan> install Image::ExifTool
>
> The following two commands will set all resolution metadata known to
> exiftool to 300.
>
> exiftool -'*Resolution'=300 image.jpg
The best workaround so far, especially, if the image data are kept
unchanged.
> I haven't done a thorough testing of this tool, but for OP's image, it
> worked. (The command might need some refinement, depending on your needs.)
>
> To just read all the metadata, do
>
> exiftool -v image.jpg
Very nice, but the interpretation of the output needs some background
knowledge from the specifications, e.g.:
JPEG APP0 (14 bytes):
+ [BinaryData directory, 9 bytes]
| JFIFVersion = 1 1
| ResolutionUnit = 1
| XResolution = 72
| YResolution = 72
The values of the "ResolutionUnit", from the specification
(http://www.w3.org/Graphics/JPEG/jfif3.pdf):
units = 0: no units, X and Y specify the pixel
aspect ratio
units = 1: X and Y are dots per inch
units = 2: X and Y are dots per cm
Result: 72 DPI
JPEG APP1 (798 bytes):
ExifByteOrder = MM
+ [IFD0 directory with 9 entries]
| 0) Make = NIKON CORPORATION
| 1) Model = NIKON D5100
| 2) Orientation = 1
| 3) XResolution = 300 (300/1)
| 4) YResolution = 300 (300/1)
| 5) ResolutionUnit = 2
That's the start of the EXIF header.
(https://en.wikipedia.org/wiki/Exchangeable_image_file_format)
ResolutionUnit can have one of two values:
2: dots per inch (DPI)
3: dots per cm
Result: 300 DPI
Yours sincerely
Heiko
More information about the XeTeX
mailing list