3 examples of unusual ways to use PDF Image Masks

Early this week, I wrote an introductory article about Masks. I would like to follow that with another article highlighting an issue which can occur with masks.

As explained before, a Mask is effectively a stencil which allows you to define which pixels are painted onto the page any how transparent they are. That is the easy bit – the problem is that the Mask and the Image can be very different sizes. It does not even need to have the same aspect ration. And there are quite a few tools which use this feature to achieve some interesting effects. Here are some examples:-

1. Specify an SMask as a 1 x 1 pixel image (the image is actually a much larger rectangle).

2. Specify a Mask with the same width as the image but a height of 1 pixel (the image is 900 pixels high).

3. Specify a large Mask and a 1×1 pixel image.

So the way we handle image Masks to cover these is to :-

  • always use the bigger set of dimensions (whether on image or Mask)
  • Scale the smaller to the larger with separate scaling on width and height
  • Do not expect the Mask and the image to have the same aspect ratio

Have you come across and odd uses of image Masks in PDF files?

This post is part of our “Understanding the PDF File Format” series. In each article, we aim to take a specific PDF feature and explain it in simple terms. If you wish to learn more about PDF, we have 13 years worth of PDF knowledge and tips, so click here to visit our series index!

Related Posts:

The following two tabs change content below.

Mark Stephens

System Architect and Lead Developer at IDRSolutions
Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX. He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.
Markee174

About Mark Stephens

Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX.

He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.

One thought on “3 examples of unusual ways to use PDF Image Masks

  1. Jim

    Great post.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>