# When generating html, how do you specify image size?

I am using htlatex (or as many people call it tex4ht) to generate html and I have included some graphics. Htlatex seems to ignore all the size arguments I give the image size. I've tried specifying:

``````width=\textwidth
width=2in
width=1024px
width=1024pt
``````

All of these have been ignored. Can you specify a size for the image when using htlatex to generate an html version of your document? If yes how does one specify the image size?

Right now I am editing each picture to be the correct size but this is bothersome... I would much rather have one high res picture and then specify a smaller size.

-
Do people usually call it htlatex or tex4ht? –  Trevor Boyd Smith Jul 27 '12 at 14:01
`tex4ht` is more general, htlatex is only one script from the bundle, there are also others –  michal.h21 Jul 27 '12 at 14:12
see tex.stackexchange.com/a/43801/2891 for some details on how `tex4ht` process images –  michal.h21 Jul 27 '12 at 14:14
–  michal.h21 Jul 27 '12 at 14:15
I think the `latex2html` tag doesn't apply to that question. –  ℝaphink Sep 14 '12 at 12:19

Following code will help you to grab the width and height dimensions of the graphic provided with your `\includegraphics` command:

`````` \makeatletter
\Configure{graphics}
{\bgroup
\Configure{IMG}
{\HCode{<img src="}}
{\HCode{" alt="}}
{" }
{\HCode{" }}
{}%
\Picture+[PIC]{}}
{\EndPicture
\HCode{ width="\expandafter\the\csname Gin@req@width\endcsname"
height="\expandafter\the\csname Gin@req@height\endcsname"
/>}%
\egroup}
\makeatother
``````
-
how do I use this Latex code? (is it a one time bit that goes in the preamble? is it a macro definition that I use each time I include a graphic? does it go in the options for `includegraphics`?) –  Trevor Boyd Smith Sep 18 '12 at 19:56
It is a one time bit to be entered in the preamble. –  CV Radhakrishnan Sep 19 '12 at 15:06
Sorry, I am unable to make this work. I put the above code into a working .cfg file, and in my tex file, the image is used as `\includegraphics[width = 2in]{figs/test.png}`, but the image still appears in fullresolution in the generated html. –  M-V Sep 23 '12 at 7:11
You need to keep *.eps versions of your figures. Since tex4ht relies on .dvi and hence dvips driver of graphicx package is made use of, only .eps files will provide all the functionality of \includegraphics. Also, remove the extension .png from your your included graphic file names. –  CV Radhakrishnan Sep 24 '12 at 7:06
With TeXLive under Ubuntu I get the error (I report just a small portion) `l.134 --- TeX4ht warning --- \Configure{graphics}? --- l.134 --- TeX4ht warning --- \Configure{IMG}? --- ` and `...such style files MUST BE UPDATED to use Current Standard LaTeX: LaTeX2e...`. –  mmj Dec 2 '13 at 10:46

Since htlatex seems to generate a DVI first, the following answer helped me: Cannot determine size of graphic

So for setting the displayed size of a 530x260 JPG image in HTML, I did:

``````\includegraphics[width=0.5\textwidth,natwidth=530,natheight=260]{image.jpg}
``````
-
A screenshot of the output would help and we appreciate full examples, not just one-line-code samples ;-) –  Christian Hupfer Aug 5 at 12:54