I generate documents from an UML tool via scripting. I already know how to scale images within a ‘#figure’ environment which helps with some images where details don’t matter. The main problem: with certain images, where high resolution and details do matter, the previous page is completely empty. Wasting lots of space is acceptable but not whole blank pages (=empty apart from header / footer). How can I find that out and react accordingly (scaling the image via ‘width’ and ‘height’)
Hello @ndg2kb, it would be helpful if you can provide a MWE.
I will try, but this may need a while. As I said, my documents are generated by script from a modeling tool, so I have to try to strip that down to a minimal example.
If you can measure the width and height of the resulting image, that would be fine! We can just draw a rectangle
Well, I already do that in a certain function (see below), which helps me to layout other images. However, in this case, I need the previous page and look whether it’s completely empty.
Other function:
#let scaled-img(imgname) = context {
let img = image(imgname)
let size = measure(img)
let ratio = size.height / size.width
if (ratio >= 1.1 and ratio < 1.7) {
image(imgname, width: 75%)
} else if (ratio >= 1.7) {
image(imgname, width: 60%)
} else {
image(imgname, width: auto)
}
}
Hi @ndg2kb,
just a question out of curiosity - do you aim to scale the image out as much as possible?
I wonder why this happens anyway - wouldn’t that behavior be a result of a spacing issue after or beforehand the image?
Typst already scales down images for me if either width or height exceed page dimensions (good!). However, in case of blank pages before a placed image, I would need to scale down that image even further (preferable not much), so I get at least a little bit of text content on that previous page.