Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image upscaled for no apparent reason #1277

Closed
bjhijmans opened this issue Feb 15, 2024 · 7 comments
Closed

Image upscaled for no apparent reason #1277

bjhijmans opened this issue Feb 15, 2024 · 7 comments

Comments

@bjhijmans
Copy link

Brief outline of the bug

I encountered an issue where an image was upscaled by about a third and I don't know why. It seems to be specific to the image, which was resized down using https://imageresizer.com/. I also used another method to scale down the same image and every other application agrees that the two included images are identical in size. But somehow, when I compile them in LaTeX there is a very obvious difference.

Minimal example showing the bug

\RequirePackage{latexbug}
\documentclass[]{article}
\usepackage{graphicx}

\begin{document}
	\begin{figure}
		\centering
		\includegraphics{SameSize(1).png}
		\caption{caption}
	\end{figure}
	
	\begin{figure}
		\centering
		\includegraphics{SameSize(2).png}
		\caption{caption}
	\end{figure}
\end{document}

I included the two images below. As you can see, they're two identical red triangles. Somewhere in LaTeX internals the decision is made that one of them should be about 33% bigger.

Log file (required) and possibly PDF file

test.log
test.pdf
SameSize(1)
SameSize(2)

@u-fischer
Copy link
Member

well I can no access the real images and without them it is difficult to say something. Probably they have different resolution. You should also check if pdflatex renders them differently too and not only xelatex.

@davidcarlisle
Copy link
Member

if you use pdflatex the size is obtained by running extractbb (which is dvipdfmx essentially), it reports

%%Creator: extractbb 20220710
%%BoundingBox: 0 0 79 150
%%HiResBoundingBox: 0.000000 0.000000 79.000000 150.000000
%%CreationDate: Thu Feb 15 10:58:12 2024

for the first and

%%Creator: extractbb 20220710
%%BoundingBox: 0 0 59 113
%%HiResBoundingBox: 0.000000 0.000000 59.258271 112.515705
%%CreationDate: Thu Feb 15 10:58:29 2024

for the second.

So it is not really a latex issue as it is being given different sizes.

The images are the same in pixel size but have different metadata setting resolution

gimp shows the first as

image

gimp shows the second as

image

@bjhijmans
Copy link
Author

@davidcarlisle that's very interesting. I will admit I don't know much about image metadata. I also accept that I may be entirely in the wrong place with this. I assumed, apparently incorrectly? that the print size would be the number of pixels divided by the DPI. Windows, at least, reports a DPI of 96 for both images and the same size in pixels.

Is the offending image's metadata internally inconsistent?

It still looks to me like LaTeX, apparently through extractbb, is looking at different data than other programs are. Is there a standard for this that someone isn't adhering to?

@muzimuzhi
Copy link
Contributor

Windows, at least, reports a DPI of 96 for both images and the same size in pixels.

imagemagick gives different answers

$ identify -units PixelsPerInch -format '%U %x,%y\n' latex2e-gh1277-1.png
PixelsPerInch 72,72
$ identify -units PixelsPerInch -format '%U %x,%y\n' latex2e-gh1277-2.png
PixelsPerInch 95.989999999999994884,95.989999999999994884

Relevant docs

@bjhijmans
Copy link
Author

I used a different resizer for the image and sent it to my customer, and it still didn't work. It turns out that Gmail also resizes images (for file size, not pixels) and it causes the exact same issue.

I wish I knew what image tools are being used under the hood so that I could submit a bug report there. Images shouldn't scale differently because they've been emailed at some point.

@u-fischer
Copy link
Member

you shouldn't sent important binary images as email attachments (or perhaps even embedded in some html). At least put them inside a zip.

@josephwright
Copy link
Member

I agree things shouldn't auto-resize, but that's not a LaTeX issue ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants