function imagecache_actions_percent_filter in ImageCache Actions 7
Same name and namespace in other branches
- 8 utility.inc \imagecache_actions_percent_filter()
Computes a length based on a length specification and an actual length.
Examples: (50, 400) returns 50; (50px, 400) returns 50; (50%, 400) returns 200; (50, null) returns 50; (50%, null) returns null; (null, null) returns null; (null, 100) returns null.
Parameters
string|null $length_specification: The length specification. An integer constant optionally followed by 'px' or '%'.
int|null $current_length: The current length. May be null.
Return value
int|null
2 calls to imagecache_actions_percent_filter()
- canvasactions_definecanvas_dimensions in canvasactions/
canvasactions.inc - Image dimensions callback for the define canvas effect.
- canvasactions_definecanvas_effect in canvasactions/
canvasactions.inc - Image effect callback for the define canvas effect.
File
- ./
utility.inc, line 539 - utility.inc: uitility form, conversion and rendering functions for image processing.
Code
function imagecache_actions_percent_filter($length_specification, $current_length) {
if (strpos($length_specification, '%') !== FALSE) {
$length_specification = $current_length !== NULL ? str_replace('%', '', $length_specification) * 0.01 * $current_length : NULL;
}
else {
// Strips 'px' if available.
$length_specification = (int) $length_specification;
}
return $length_specification;
}