This patch solves two related issues I ran into.

Issue 1: Most of my themes use an underlying grid structure with both fixed columns (horizontal) and a baseline (vertical) value. I wanted a way to resize images to snap to both axis while keeping their relative dimensions. I introduced a ‘snap-x’ value that lets you resize your image to the nearest point on your grid.
For example, if you have a horizontal grid every 50px and a baseline grid of 18px you can build a filter in two steps:
1: scale the image down to a width of 150px (3 cols wide) with no height value
2: crop the image to a height value of ‘snap-18’.
This will create an image that fits precisely on my underlying grid.

Issue 2: After resizing an image to fit perfectly on my grid I sometimes need to add a border to the image with CSS (e.g. border: 5px;). The border would then render outside my grid boundaries. So I created another filter (‘remove-x’)that I use after the two steps described above.
3. Scale the image again with a width and height value set to ‘remove-10’
This just shaves off the exact amount so that my image and border together fit nicely in my grid again.

I hope this is useful to others.

Comments

mason@thecodingdesigner.com’s picture

StatusFileSize
new4.09 KB

For some reason my uploaded patch file didn't show up. Attaching here.

drewish’s picture

why did you edit the existing function rather than making a copy and adding your changes there?

mason@thecodingdesigner.com’s picture

Thanks for checking out my patch.

I edited the function because I felt that what I was doing was expanding on the intent of the orginal '_imagecache_percent_filter()' function, which I see as finding a new pixel dimension based on a keyword (originally just '%') in the submission. Changing the function name to '_imagecache_dimension_filter()' seemed like a direct way to build on that while keeping the code uncomplicated.

I assume tho, that you're bring this up because it might break someone else's work to change the function name. I'll admit I hadn't considered that while writing this originally. If that's the case then I can reconsider my technique and work out another way.

mason@thecodingdesigner.com’s picture

I broke the functionality up into discrete filter functions. I think it's a little cleaner now.

mason@thecodingdesigner.com’s picture

I've moved my development to imagecache version 2: http://drupal.org/node/257111

drewish’s picture

Version: 5.x-1.5 » 5.x-2.x-dev

marked #257111 as a duplicate of this, you should just change the version and keep it all on one issue.

mason@thecodingdesigner.com’s picture

thanks, will do in the future.

fizk’s picture

Status: Needs review » Closed (won't fix)