Ppvimage

From DPWiki
Jump to navigation Jump to search

This little perl program is intended to make some of the work in PPV a bit easier, but can also be helpful to PPers. The code borrowed heavily from rfrank's ppvtxt and ppvhtml tools and includes various bits of code posted elsewhere on the internet.

It can be used standalone, with a simple graphical interface: just run ppvimage.pl and follow the displayed instructions. It can also be used as a command-line tool (following a suggestion of Katt83), and thanks to hanne and windymilla has been integrated into GuiGuts.

The program goes through an html file and checks all the <img> tags, reporting the dimensions coded in the html, the natural dimensions of the image (these should normally be the same), the image filesize, and the contents of the alt and title tags.

----- checking <img> images -----

Image: images/illus-001.png
  (line 219)
  alt=""
  title="Frontispiece"
    coded width="453" height="700"
  natural width="453" height="700"
  Filesize:  52 KB

The width and height are reported with surrounding quotes so that they can be easily pasted into the <img> tag if a correction is necessary. The program can also recognise dimensions provided via inline CSS (instead of by way of the width and height attributes of the <img> tag) but you have to put up with being told continually that the <img> attributes are missing. It's not clever enough to pick up dimensions declared in header css.

Basic information on images declared using a css background-image spec is also reported.

----- checking css background images -----

Background image: images/strip.png
  (line 142)
  natural width="600" height="55"
  Filesize:   2 KB

Basic information about images that are the destination of a link is also provided.

---------- checking linked images ----------

Linked image: images/pl14h.jpg
  (line 803)
  natural width="1203" height="677"
  Filesize: 1247 KB (LARGE)

The tool also checks that an epub cover image has been specified, and performs a check for files in the /images folder that are not referenced in the html file.

If a project includes a large number of images, this output can be a bit daunting. Following a suggestion by Cosmas, the essential information can also be output as a CSV (comma separated values) file, to make it easier to locate differences between natural and coded dimensions by feeding the CSV file into a spreadsheet.

The tool can also be used from the command line. The syntax is

perl -w ppvimage.pl [-csv] [-terse] [-o logfile.txt] filename.html
  • The optional -csv argument adds the CSV output.
  • The optional -terse argument suppresses some of the purely informational output.
  • The optional -o argument allows you to specify a destination for the log file. If omitted, this defaults to ppvimage.log in the same folder as the filename.html input.