Document Actions Series: ScaleImageToFill
Image scaling, in your Pageflex projects, has steadily improved over time. After beginning with just “Fit Width” and “Fit Height”, we now have options such as “Scale to Fit”. Usually, these options are enough to guarantee your printed product output renders well. However, there are complications that arise when the user is allowed to upload their own photo. Ensuring ratios are met and applied with the built in image scaling options can frequently be troublesome. Knowing these complications, Pageflex built and released a new document action that will solve many of these problems.
Using the published document action from Pageflex, I changed some of the functionality and imported it into the Four51 Document Actions library. The goal was to make it more flexible and targeted, as well as work more similarly to the existing actions in the library. Due to the unique nature of this document action I thought a blog post was in order. Of course, you should use the wiki as a reference guide.
What does this document action actually do? It’s actually pretty simple. First it gathers the size (width and height) of the image and it’s parent (area template). It then compares those sizes to determine the greater difference between the two ratios. If the height ratio is larger then the image will be scaled to the height of the area template, and vice versa for when the width is greater. This scaling will obviously leave the image larger than the area template in which it’s contained, but this is desired. The area template will crop the excess image area, leaving the entire area template filled with the area the image fits.
The anchor point property of the image controls how the image will be cropped. If the anchor point is set to Center/Middle it will be cropped evenly on all sides. If the anchor point is set to Left/Top the image will be cropped on the right and bottom.
Special recognition for this solution goes to Pageflex. It was their idea and source code that forms the basis for this offering.
This document action example can be viewed and downloaded at the demo site. The product is named “Documents Actions Scale Image To Fill”.

Popularity: 92%
Previous post in category Next post in category

Comment by Penny Holman on 10 March 2010:
I don’t see an example using this document action in the demo site. Has it been removed?
Comment by Steve on 11 March 2010:
Sorry about that. During a recent pageflex upgrade the document action needed a bug fix and I forgot to reactivate that product. It’s there now.