Aspect Switcher -- Allow Weighted Comparison
| Project: | Imagecache Actions |
| Version: | 6.x-1.5 |
| Component: | Canvas Actions Module |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Jump to:
Thanks for building this super-useful module in a clean and extensible way.
One particular need we had is to produce a fixed 90x50 image, first scaling to the right dimensions, then by cropping one of them.
Because we wanted to avoid having to do padding (neither black or white bars were desirable), we needed to figure out whether it's the width or the height was smaller relative to the 9:5 ratio, and scale by it, and then crop by the other (larger) dimension. The aspect switcher action did almost what we needed, but it didn't allow us to specify the ratio we cared about.
We added a parameter "scale_height" that is used as a multiplier for the height when comparing it to the width.
So in our case, the value we had to enter was 140 (9/5 * 100).
The setting name and description in the following patch probably should be reworded.
<?php
Index: site/sites/all/modules/imagecache_actions/canvasactions.inc
===================================================================
--- imagecache_actions/canvasactions.inc (revision 3349)
+++ imagecache_actions/canvasactions.inc (working copy)
@@ -697,6 +697,7 @@
* @return a form definition
*/
function canvasactions_aspect_form($action) {
+ $defaults = array( 'scale_height' => 100 );
$action = array_merge($defaults, (array)$action);
$form = array(
@@ -724,6 +725,14 @@
'#options' => $presets,
);
+ $form['scale_height'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Scale height'),
+ '#default_value' => $action['scale_height'],
+ '#size' => 6,
+ '#description' => t('If you\'d rather scale the height by a multiplicative factor for the purposes of comparison, enter it here as a percentage (ie 100 will preserve the height)'),
+ );
+
return $form;
}
@@ -747,7 +756,11 @@
* @param $action
*/
function canvasactions_aspect_image(&$image, $action = array()) {
- $preset_id = ($image->info['width'] > $image->info['height'] ) ? $action['landscape'] : $action['portrait'];
+ $scale_height = (int) $action['scale_height'];
+ if(!$scale_height) {
+ $scale_height = 100;
+ }
+ $preset_id = ($image->info['width'] > ($image->info['height'] * $scale_height / 100) ) ? $action['landscape'] : $action['portrait'];
$preset = imagecache_preset($preset_id);
// Run the preset actions ourself. Cannot invoke a preset from the top as it handles filenames, not image objects.

#1
Accidentally set assign status.
#2
Interesting. Sounds like a good idea, if extremely rare. I thought my aspect switcher was a special case!
I can see what you are doing, and the code is good and simple. The hard part is explaining what's going on in words on the UI :-)
I'm thinking the ratio adjustment should be a decimal, not a percentage.
#3
I think you've put it really well, much better than I could have.
#4
Hi, if I choose left or right xpos, the underlay image is always positioned left. I've tested this with an image of 140px wide and an underlay image slightly larger at 170px.
Sack
#5
How is this related to the aspect switcher?
You'll need to actually paste up your settings and a screenshot, because I can't guess what you mean. The aspect switcher does not affect the underlay.
Are you wanting to start a completely new unrelated issue?
#6
Yeah sorry, I was meant to make a new issue ;)
#7
Renaming - putting this back on the table. I wanted to get it in, but forgot.