| 1 |
<?php
|
| 2 |
// $Id: imageapi.module,v 1.25 2009/02/06 09:26:33 drewish Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
*
|
| 7 |
* An ImageAPI supporting additional image plugins as modules.
|
| 8 |
* Images are treated as objects, and images are not written per
|
| 9 |
* manipulation as Drupal's core image handling works.
|
| 10 |
*
|
| 11 |
*
|
| 12 |
* imageapi image api workflow...
|
| 13 |
* $image = imageapi_image_open($path) to get an image object for $path...
|
| 14 |
* image_X($image, $arg1, $arg2) to manipulate image object...
|
| 15 |
* imageapi_image_close($image) to overwrite original image.
|
| 16 |
*
|
| 17 |
*/
|
| 18 |
|
| 19 |
/**
|
| 20 |
* Sharpen an image given some sharpening parameters.
|
| 21 |
*
|
| 22 |
* NOTE: These parameters only have an effect when Imagemagick is used.
|
| 23 |
* GD will used a fixed convolution matrix as described in imageapi_gd.module
|
| 24 |
*
|
| 25 |
* @param $image
|
| 26 |
* An imageapi image object returned by imageapi_image_open().
|
| 27 |
* @param $radius
|
| 28 |
* The radius of the gaussian, in pixels, not counting the center pixel. (default 0.5)
|
| 29 |
* @param $sigma
|
| 30 |
* The standard deviation of the gaussian, in pixels. (default 0.5)
|
| 31 |
* @param $amount
|
| 32 |
* The percentage of the difference between the original and the blur image that is
|
| 33 |
* added back into the original. (default 100)
|
| 34 |
* @param $threshold
|
| 35 |
* The threshold, as a fraction of max RGB levels, needed to apply the difference
|
| 36 |
* amount. (default 0.05)
|
| 37 |
* @return
|
| 38 |
* True or false, based on success.
|
| 39 |
*/
|
| 40 |
function image_sharpen(&$image, $radius, $sigma, $amount, $threshold) {
|
| 41 |
return image_toolkit_invoke('sharpen', $image, array($radius, $sigma, $amount, $threshold));
|
| 42 |
}
|
| 43 |
|
| 44 |
/**
|
| 45 |
* Convert a hex string to its RGBA (Red, Green, Blue, Alpha) integer
|
| 46 |
* components.
|
| 47 |
*
|
| 48 |
* @param $hex
|
| 49 |
* A string specifing an RGB color in the formats:
|
| 50 |
* '#ABC','ABC','#ABCD','ABCD','#AABBCC','AABBCC','#AABBCCDD','AABBCCDD'
|
| 51 |
* @return
|
| 52 |
* An array with four elements for red, green, blue, and alpha.
|
| 53 |
*/
|
| 54 |
function imageapi_hex2rgba($hex) {
|
| 55 |
$hex = ltrim($hex, '#');
|
| 56 |
if (preg_match('/^[0-9a-f]{3}$/i', $hex)) {
|
| 57 |
// 'FA3' is the same as 'FFAA33' so r=FF, g=AA, b=33
|
| 58 |
$r = str_repeat($hex{0}, 2);
|
| 59 |
$g = str_repeat($hex{1}, 2);
|
| 60 |
$b = str_repeat($hex{2}, 2);
|
| 61 |
$a = '0';
|
| 62 |
}
|
| 63 |
elseif (preg_match('/^[0-9a-f]{6}$/i', $hex)) {
|
| 64 |
// #FFAA33 or r=FF, g=AA, b=33
|
| 65 |
list($r, $g, $b) = str_split($hex, 2);
|
| 66 |
$a = '0';
|
| 67 |
}
|
| 68 |
elseif (preg_match('/^[0-9a-f]{8}$/i', $hex)) {
|
| 69 |
// #FFAA33 or r=FF, g=AA, b=33
|
| 70 |
list($r, $g, $b, $a) = str_split($hex, 2);
|
| 71 |
}
|
| 72 |
elseif (preg_match('/^[0-9a-f]{4}$/i', $hex)) {
|
| 73 |
// 'FA37' is the same as 'FFAA3377' so r=FF, g=AA, b=33, a=77
|
| 74 |
$r = str_repeat($hex{0}, 2);
|
| 75 |
$g = str_repeat($hex{1}, 2);
|
| 76 |
$b = str_repeat($hex{2}, 2);
|
| 77 |
$a = str_repeat($hex{3}, 2);
|
| 78 |
}
|
| 79 |
else {
|
| 80 |
//error: invalide hex string, TODO: set form error..
|
| 81 |
return false;
|
| 82 |
}
|
| 83 |
|
| 84 |
$r = hexdec($r);
|
| 85 |
$g = hexdec($g);
|
| 86 |
$b = hexdec($b);
|
| 87 |
$a = hexdec($a);
|
| 88 |
return array($r, $g, $b, $a);
|
| 89 |
}
|
| 90 |
|