# Global scaling of images in html output (only) of htlatex

I have the following MWE with some images:

\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}
\end{centering}
\end{document}


which compile as expected with pdflatex myfile.tex to pdf output, with one image half of the text width and the other same width as text. Then, using the following config file (needed to obtain images with correct relative sizes):

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


I compile the same source with htlatex myfile myconfig, in order to obtain an html version of my document. Image sizes are correct among themselves, but they are too small compared to text size. I guess this has something to do with the fact that html has not a fixed page width, so tex4ht has to choose a value to be used has 'page width', and such value is too small, at least for me.

Is there a 'TeX way' to scale all images in html output by a factor?

Of course I could increase the width of images in my latex source, but that would be time consuming and would affect pdf too, which is undesiderable.

Or I could write some external script to parse html output and manipulate image sizes in html source, but I'd prefer a TeX-confined solution.

Someone might like to be informed that the present question arised from this other question.

UPDATE

Given that many days have passed with no answers, I'll open the question to answers which are not TeX-confined. See below for a possible solution.

Adopting the external script workaround, other issues arised, which luckily found a solution. Basically you have to use a configuration file able to take care of all the image format you have. Here is myconfig.cfg updated in order to take care of jpg, png and eps image formats:

\Preamble{xhtml}
\Configure{graphics*}
{jpg}
{\Picture[pict]{\csname Gin@base\endcsname.jpg
\space width="\expandafter\the\csname Gin@req@width\endcsname"}}
\Configure{graphics*}
{png}
{\Picture[pict]{\csname Gin@base\endcsname.png
\space width="\expandafter\the\csname Gin@req@width\endcsname"}}
\Configure{graphics*}
{eps}
{\Needs{"convert -density 110x110 \csname Gin@base\endcsname.eps \csname Gin@base\endcsname.png"}
\Picture[pict]{\csname Gin@base\endcsname.png
\space width="\expandafter\the\csname Gin@req@width\endcsname"}}
\begin{document}
\EndPreamble


And here is my post-production Python script able to multiply by a factor width and height attributes of images in html source:

#!/usr/bin/python
# usage under Ubuntu 12.04 with Python 3.2: python3 fixhtml.py my_html
# requirement: my_html file is expected to be UTF-8 encoded text file

import sys,re
import os.path

if len(sys.argv)!=2:
print("You need to specify the HTML file you want to process when you call 'fixhtml'. Try again.")
sys.exit()
fn=sys.argv[1]
if not os.path.exists(fn):
sys.exit()

print("Processing HTML file '"+fn+"'...")
f=open(fn,'r',encoding="utf-8")
f.close()

def fixall(text,searchpatt,subpatt,factor,factor_group):
m=re.search(searchpatt,text)
fixed_text=''
while m:
value=m.group(factor_group)
new_value=factor*float(value)
fixed_text+=re.sub(searchpatt,subpatt%new_value,text[:m.end()])
text=text[m.end():]
m=re.search(searchpatt,text)
return fixed_text+text

factor=2.0 # images enlargement factor
factor_group=2 # factor is found in second group of regex search expression
htmltext=fixall(htmltext,'(?ms)img(.+?)width.*?=.*?"([^"a-zA_Z]+)([a-z]{1,3})"',r'img\1width="%.4f\3"',factor,factor_group) # change the last 3 arguments to suit your needs
htmltext=fixall(htmltext,'(?ms)img(.+?)height.*?=.*?"([^"a-zA_Z]+)([a-z]{1,3})"',r'img\1height="%.4f\3"',factor,factor_group) # each line one passage: add as many you want

import codecs
f = codecs.open("fixed_"+fn,'w',encoding='utf8') # output file name is the same as input with the prefix 'fixed_', file is overwritten if existing
f.write(htmltext)
f.close()