# Setting image size in html output of tex4ht

I have a complex document which I'm trying to convert to html with tex4ht and TeXLive under Ubuntu, but I'm not able to coherently control the image size of jpg and eps images. In html output, jpg images get direct reference to original image and seems to display at 1 to 1 pixel, while eps images are converted into a png image whose size is specified in html but seems to display too small. In both (or at least some) cases the original \includegraphics[width=mymeasure]{myimage.jpg-eps} specification isn't respected. I've tried a lot of tricks, configurations and snippets (like this and this) without success.

Is it possible to transfer the size specified for images in LaTeX source to html output?

Here is my MWE:

\documentclass{book}
\usepackage{graphicx}
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipisici elit:
\begin{centering}
\includegraphics[width=0.5\textwidth]{myimage.jpg}

\includegraphics[width=1.0\textwidth]{myimage.jpg}

\includegraphics[width=0.5\textwidth]{myimage.eps}

\includegraphics[width=1.0\textwidth]{myimage.eps}
\end{centering}
\end{document}


which I compile with htlatex myfile.

And here is the html output.

As you can see, the big (as well as the small) jpg and eps images should have the same (100%) width, whereas they don't (in html, but they do in the pdf).

Also, the two jpg images should have one the half width of the other, whereas they don't (in html, but they do in the pdf).

-

This works correctly for me with TeX Live 2012 on Linux.

\documentclass{book}
\usepackage{graphicx}
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipisici elit:

\begin{centering}
\includegraphics[width=.7\textwidth]{myimage.eps}\\
\includegraphics[width=.3\textwidth]{myimage.eps}\\
\includegraphics[width=1.0\textwidth]{myimage.eps}\\
\end{centering}

\the\dimexpr .7\textwidth\relax
\end{document}


Resulting html:

<p class="noindent" ><img
src="epss0x.png" alt="PIC" class="graphics" width="241.49895pt" height="169.62851pt"  /><!--tex4ht:graphics
name="epss0x.png" src="myimage.eps"
--><br />
<img
src="epss1x.png" alt="PIC" class="graphics" width="103.50105pt" height="72.6991pt"  /><!--tex4ht:graphics
name="epss1x.png" src="myimage.eps"
--><br />
<img
src="epss2x.png" alt="PIC" class="graphics" width="345.0pt" height="242.3276pt"  /><!--tex4ht:graphics
name="epss2x.png" src="myimage.eps"
--><br />
</p><!--l. 13--><p class="indent" >   241.49895pt</p>


Note that width=.7\textwidth and \the\dimexpr .7\textwidth\relax are producing the same value: 241.49895pt.

Regarding jpg images, dimension information isn't saved for some reason. But we can use custom config file:

\Preamble{xhtml}
\Configure{graphics*}
{jpg}
{%
\Picture[pict]{\csname Gin@base\endcsname .jpg
\space width="\the\dimexpr \expandafter\csname Gin@req@width\endcsname * 1.5"
}%
}
\Configure{graphics*}
{png}
{%
\Picture[pict]{\csname Gin@base\endcsname .png
\space width="\expandafter\the\csname Gin@req@width\endcsname"
}%
}
\begin{document}
\EndPreamble


This will increase seze of the included image by factor os 1.5. Save it as myconf.cfg and compile the source file with

htlatex myfile myconf

-
Thanks for your right observation, it helped me to better focus the problem, which remains. See the question I updated accordingly. –  mmj Dec 6 '13 at 15:26
It worked, thanks! Adding your config snippet and compiling with it, jpg images resized accordingly to eps images, so I guess there no eps bounding box issue. Only one detail: adding config code for png as you said, a strange line ('png pict') shows up at beginning of html. Maybe it's because I don't actually have any png image? (but I will in real document) Could you add png to your config code to make sure I used the right code? (and that you don't have such issue) –  mmj Dec 10 '13 at 18:30
@mmj I edeted the config file to show the png configuration –  michal.h21 Dec 10 '13 at 19:04
Thanks, I did not duplicate the \Configure{graphics*} row. No doubt you brilliantly solved this problem, nonetheless the 1.0\textwidth image width is smaller than I wish, when I compare it with font size, in html output. Is there a way to tell tex4ht to scale all images by a factor? –  mmj Dec 10 '13 at 22:16
@mmj you can try to use make4ht image conversion (github.com/michal-h21/make4ht#image-conversion) and specify output resolution for dvipng (with -D option) –  michal.h21 Dec 11 '13 at 9:48