Determine graphics file resolution.
Just making a quick post to cover something I found earlier. Chatting to a user in #latex on Freenode about inserting pictures in to $\LaTeX$ documents. It seems scaling the image isn't an issue as long as you know the actual picture resolution.
gives the following example on how to insert a picture in to a $\LaTeX$ document
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\includegraphics[width=\textwidth]{YOUR-FILE-NAME-HERE}
\end{document}
We can reduce this slightly by removing the \textwidth element
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\includegraphics[width=0.5]{YOUR-FILE-NAME-HERE}
\end{document}
Which will scale the image and insert at ½ the width.
In overleaf and on a GUI it is easy to obtain the image properties.
If you're at the cli, and therefore not able to do this, what do you do then.
There are several solutions
- Graphics Magic
gm identify file.png will return some information including the file resolution:
gm identify hexchatSASL.png
hexchatSASL.png PNG 432x549+0+0 DirectClass 8-bit 45.2Ki 0.000u 0m:0.000003s
So on a similar note the file command does something similar
file hexchatSASL.png
hexchatSASL.png: PNG image data, 432 x 549, 8-bit/color RGB, non-interlaced
You can also use the view command, which is part of midnightcommander, so opens up a graphical application to display image data.
Once you have determined the file resolution you can calculate how much you need to scale the image.
If you had an image at say 640x480 (w x h) then and you want to display this at ½ the width. Then you can insert
\includegraphics[width=0.5]{YOUR-FILE-NAME-HERE}
To calculate the displayed size you can use
$0.5 \times 640 = 320$
So in this example your image will display, with a width of 320 pixels in your document.
If you use 0.75 then the width is going to be 480
$0.75 \times 640 = 480$
Hopefully this will help someone out there. I did something useful while helping with this.