Forum How do I...?

select images based on DPI

thespacecamel
I'm aware Prince can set an image's DPI using `-prince-image-resolution`, but I'm wondering if it's possible to instead use a CSS selector based on an image's DPI?
Eg, I'd like to detect all images whose DPI is too low, and automatically add a red border to them, to help the document author identify those images that don't meet the DPI requirement. I believe Adobe InDesign can do this.
Right now the best I can do it just set all image's DPI, and a maximum size so they don't overflow the alloted space, and the document author will need to spot the images that look smaller than they'd like (because of the DPI resizing).
Thoughts on this?
mikeday
I don't think there is any way to do this yet, I wonder do browsers have any JavaScript APIs that allow you to retrieve the pixel dimensions of a given image?
LMischler
Maybe I miss something, but don't you think this might be achieved with 2-pass rendering, using the box tracking api?

After the first pass, the registerPostLayoutFuncfunction function could use the box tracking information to check each image:
  • get each box of type "IMAGE"
  • get the related box size to know the printed dimension of that image
  • get the corresponding <img> DOM element, and use javascript .naturalWidth to get the original width of the source image in px
  • then you can divide to get the ppi of that image, compare to your required minimum value, and if below, add a class like "low-ppi" to that image, which will be used to add a red border to those images during the second rendering done by Prince.
mikeday
Prince doesn't support the "naturalWidth" property yet, but yes that sounds like a viable approach once we do!