5

is there a way to specify the maximum width of images in a docbook xsl-transform?

we have a problem with screen shots being to big to fit on a page, and thus would like to set a max width on images in the output.

specifying the width of the image in the Docbook XML files seems bad form (the Docbook file should be about content not presentation), a lot of manual work, and likely inconsistent sizes

so is there a handy way to do this?

image.default.width is not usefull because that alters images smaller then the 'page' width as well.

pvgoddijn
  • 12,638
  • 15
  • 47
  • 56
  • I believe David answered your question. You should mark it as such so folks like me immediately know what to copy/paste ;) – jww Nov 04 '13 at 19:33

2 Answers2

4

Try <imagedata width="100%" scalefit="1">. It's on each image in the source XML I know, but it will scale with various output media sizes.

Check out this page on image sizing

carillonator
  • 4,715
  • 3
  • 29
  • 39
  • +1 for mentioning Bob Stayton's book. Images usually (ok, bitmap images) tend to have a fixed size so referring to it doesn't seem to be a bad thing. – Nic Gibson Dec 06 '09 at 19:50
  • thanks for the suggestion but this scales all images to the specified width. but i was looking to only scale images which dont fit. +1 for the book link tho – pvgoddijn Jan 05 '10 at 15:47
4

A previous answer got very close with the correct link but missed the critical phrase on that page:

To keep a graphic for printed output at its natural size unless it is too large to fit the available width, in which case shrink it to fit, use scalefit="1", width="100%", and contentdepth="100%" attributes.

That suggestion works well for a PDF generated by fop. If you're also generating HTML documentation, you'll have to add the following CSS:

img {
    max-width: 100%;
    width: auto;
    height: auto;
}

You can include CSS via:

$ xsltproc --stringparam html.stylesheet doc.css ...
Community
  • 1
  • 1
David Citron
  • 43,219
  • 21
  • 62
  • 72