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.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | imagecache_grid_filters - version 2.patch | 4.5 KB | mason@thecodingdesigner.com |
| #1 | imagecache_grid_filters.patch | 4.09 KB | mason@thecodingdesigner.com |
Comments
Comment #1
mason@thecodingdesigner.com commentedFor some reason my uploaded patch file didn't show up. Attaching here.
Comment #2
drewish commentedwhy did you edit the existing function rather than making a copy and adding your changes there?
Comment #3
mason@thecodingdesigner.com commentedThanks 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.
Comment #4
mason@thecodingdesigner.com commentedI broke the functionality up into discrete filter functions. I think it's a little cleaner now.
Comment #5
mason@thecodingdesigner.com commentedI've moved my development to imagecache version 2: http://drupal.org/node/257111
Comment #6
drewish commentedmarked #257111 as a duplicate of this, you should just change the version and keep it all on one issue.
Comment #7
mason@thecodingdesigner.com commentedthanks, will do in the future.
Comment #8
fizk commented