Page 1 of 1

PHP colormatriximage

Posted: 2017-01-02T13:43:59-07:00
by Core
I am trying to write the server element which will render a image constructed in Flash. I'm using ColorMatrixFilter in AS3 but it takes a 4x5 matrix, whereas the PHP version takes 5x5. I don't understand what the 5th row is? I think the last column is brightness. I don't understand how ColorMatrixFilter works on AS3 either but this is what I have

[flash=] _SafeStr_10115 = new Map();
_SafeStr_19559("dark_sepia", _SafeStr_19546, [0.4, 0.4, 0.1, 0, 110, 0.3, 0.4, 0.1, 0, 30, 0.3, 0.2, 0.1, 0, 0, 0, 0, 0, 1, 0], null);
_SafeStr_19559("increase_saturation", _SafeStr_19546, [2, -0.5, -0.5, 0, 0, -0.5, 2, -0.5, 0, 0, -0.5, -0.5, 2, 0, 0, 0, 0, 0, 1, 0], null);
_SafeStr_19559("increase_contrast", _SafeStr_19546, [1.5, 0, 0, 0, -50, 0, 1.5, 0, 0, -50, 0, 0, 1.5, 0, -50, 0, 0, 0, 1.5, 0], null);
_SafeStr_19559("shadow_multiply_02", _SafeStr_19547, null, BlendMode.MULTIPLY);
_SafeStr_19559("color_1", _SafeStr_19546, [0.393, 0.769, 0.189, 0, 0, 0.349, 0.686, 0.168, 0, 0, 0.272, 0.534, 0.131, 0, 0, 0, 0, 0, 1, 0], null, 1);
_SafeStr_19559("hue_bright_sat", _SafeStr_19546, [1, 0.6, 0.2, 0, -50, 0.2, 1, 0.6, 0, -50, 0.6, 0.2, 1, 0, -50, 0, 0, 0, 1, 0], null, 1);
_SafeStr_19559("hearts_hardlight_02", _SafeStr_19547, null, BlendMode.HARDLIGHT, 1);
_SafeStr_19559("texture_overlay", _SafeStr_19547, null, BlendMode.OVERLAY, 1);
_SafeStr_19559("pinky_nrm", _SafeStr_19547, null, BlendMode.NORMAL, 1);
_SafeStr_19559("color_2", _SafeStr_19546, [0.333, 0.333, 0.333, 0, 0, 0.333, 0.333, 0.333, 0, 0, 0.333, 0.333, 0.333, 0, 0, 0, 0, 0, 1, 0], null, 2);
_SafeStr_19559("night_vision", _SafeStr_19546, [0, 0, 0, 0, 0, 0, 1.1, 0, 0, -50, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], null, 2);
_SafeStr_19559("stars_hardlight_02", _SafeStr_19547, null, BlendMode.HARDLIGHT, 2);
_SafeStr_19559("coffee_mpl", _SafeStr_19547, null, BlendMode.MULTIPLY, 2);
[/flash]


The third argument is the colour matrix.

Re: PHP colormatriximage

Posted: 2017-01-02T14:26:38-07:00
by fmw42
see
http://www.imagemagick.org/script/comma ... lor-matrix
http://designstacks.net/color-matrix

Other two elements besides the main RGB are alpha and constant offsets

Re: PHP colormatriximage

Posted: 2017-01-02T14:40:43-07:00
by snibgo
In IM "-color-matrix", the matrix rows represent output, and columns represent input. For RGB images, the 5 rows and columns are: red, green, blue, alpha, and offset. For example, if the first row has values "a,b,c,d,e" then the output red channel will be:

R' = a*R + b*G + c*B + d*A + e

where R,G,B and A are the input values.

The final row of the 5x5 matrix is meaningless.

Re: PHP colormatriximage

Posted: 2017-01-04T13:35:12-07:00
by Core
snibgo wrote:In IM "-color-matrix", the matrix rows represent output, and columns represent input. For RGB images, the 5 rows and columns are: red, green, blue, alpha, and offset. For example, if the first row has values "a,b,c,d,e" then the output red channel will be:

R' = a*R + b*G + c*B + d*A + e

where R,G,B and A are the input values.

The final row of the 5x5 matrix is meaningless.
Would you mind showing me an example? For a function with the following params

function($image, $flash_array, $alpha = 255)

I can't seem to get it working x(!
alpha = alpha of the colour matrix

Re: PHP colormatriximage

Posted: 2017-01-04T15:53:52-07:00
by fmw42
Play with the online interactive color-matrix at http://designstacks.net/color-matrix. That should allow you to figure it out.

Re: PHP colormatriximage

Posted: 2017-01-04T16:52:32-07:00
by snibgo
I haven't use ActionScript for years. Looking at the link Fred gave, the differences to IM seem to be:

In AS, the offset is typically in the range 0 to 255. In IM, this corresponds to 0.0 to 1.0.

In IM "-color-matrix", I generally use 6x6 matrices. For RGB images, the six columns and rows are: red, green, blue, alpha, unused, offset.

Re: PHP colormatriximage

Posted: 2017-01-04T19:34:33-07:00
by fmw42
I think snibgo is correct, in IM the offsets are in the range 0 to 1.

The IM matrix uses 6x6 to permit c,m,y,k,alpha,offset for a CMYKA image

For RGBA image if you need the offset, then you can use 5x5. If no offset, then 4x4 and if no alpha, then 3x3 are permitted.