Page 1 of 3
Edit image in Flash and Using Imagemagick at backend
Posted: 2008-06-19T13:31:04-07:00
by xhe
I want to create an application to allow user to edit images locally and send request to backend and using imageMagick to update actual image. I want to use Flash as local application, and once finished, send a http request to backend php, and then using commandline exec() to update images in server actually. Just like that of Flickr.
If this process is feasible, I having following questions:
1. My hosting provider only have ImageMagick 6.0.4, I know it is way to old, but can I still use that?
2. I can not find -recolor operation when using convert, is this only available to 6.3 or above? If so, any other alternatives in 6.0.4?
3. I used Flash
new ColorMatrixFilter([1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0.4,0]), but when I passed this matrix to imageMagick -recolor, the result is totally different. Does that mean in Flash colormatrixFilter and ImageMagick -recolor matrix, they have different meaning?
I don't have any php extension in my hosting provider, so I can only use commandline utilities.
If you can point me to some tutorial on how to realize the desired function, I will greatly appreciate it.
Thanks very much in advance.
Re: Edit image in Flash and Using Imagemagick at backend
Posted: 2008-06-19T18:56:24-07:00
by anthony
the -recolor operator has been broken in some specific version of IM.
Try the following example, and see if you get a 'grey' image...
Code: Select all
convert rose: -recolor '.2 .5 .3 .2 .5 .3 .2 .5 .3' gray_recolor.png
if it isn't grey, your IM -recolor is broken, upgrade ASAP.
Also there was a very recent fix for the handling of CMYK.
Re: Edit image in Flash and Using Imagemagick at backend
Posted: 2008-06-19T20:31:21-07:00
by xhe
No my result is convert: unrecognized option `-recolor'.
I think 6.0.4 does not support -recolor
I contacted my hosting provider, they refused to upgrade to latest version.
I tried to install on my own account, I used ./configure -prefix=/home/xxx/ and then use make install, this is some errors;
/usr/bin/ld: skipping incompatible /usr/X11R6/lib/libX11.so when searching for - lX11
/usr/bin/ld: skipping incompatible /usr/X11R6/lib/libX11.a when searching for -l X11
/usr/bin/ld: cannot find -lX11
What does this mean? Does this mean for latest version, I need to install some library first? If so, are there any rpm package that install all the required libraries already?
Thanks
Re: Edit image in Flash and Using Imagemagick at backend
Posted: 2008-06-19T22:01:36-07:00
by anthony
Your IM is old in the extreme. At least three years old!!!
I hadn't even married yet when IM was at the version!
Re: Edit image in Flash and Using Imagemagick at backend
Posted: 2008-06-20T05:38:49-07:00
by xhe
I agree it is antique.
But my hosting provider refused to upgrade it! In order to install it in my own account in a shared hosting server with the old version also available, anything I need to follow?
I checked the posting for installing on shared hosting server here, not many. So can anyone please provide me with some instruction on how to install on shared server?
Do I need to install any libraries first?
Thanks
Re: Edit image in Flash and Using Imagemagick at backend
Posted: 2008-06-22T22:03:21-07:00
by anthony
You have two choices, a "installed" and "uninstalled" version.
The difference is is the installed prefix is hardcoded as a system install, or it comes from the user defined $MAGICK_HOME environment variable.
For the later (using an enviornment varible build and install IM using the --disable-installed configuration option.
I myself prefer to do a system install using a --prefix configuration option to specify the top level install directory.
The important thing however is that BOTH your PATH environemtn varable and the LD_LIBRARY_PATH environemtn variables specifies to use YOUR installation BEFORE any other system installed version. that is try not to MIX the two versions.
I have raw notes on in
http://www.cit.gu.edu.au/~anthony/info/ ... gick.hints
Re: Edit image in Flash and Using Imagemagick at backend
Posted: 2010-03-26T11:29:11-07:00
by xtonic
Good day.
I faced the sameproblem recently. It seems that colormatrix in AS3(flash) and IM's recolor are differs in some way.
Just tried 'grey' paatern ('.2 .5 .3 .2 .5 .3 .2 .5 .3') and it worked well.
Now having hard time to determine what exactly is the difference.
Flash docu says that colormatrix computed by that formula:
Code: Select all
redResult = (a[0] * srcR) + (a[1] * srcG) + (a[2] * srcB) + (a[3] * srcA) + a[4]
greenResult = (a[5] * srcR) + (a[6] * srcG) + (a[7] * srcB) + (a[8] * srcA) + a[9]
blueResult = (a[10] * srcR) + (a[11] * srcG) + (a[12] * srcB) + (a[13] * srcA) + a[14]
alphaResult = (a[15] * srcR) + (a[16] * srcG) + (a[17] * srcB) + (a[18] * srcA) + a[19]
while IM docu also doesnt say very much:
RecolorImage() translate, scale, shear, or rotate image colors. Although you can use variable sized matrices, typically you use a 5 x 5 for an RGBA image and a 6x6 for CMYKA. Populate the last row with normalized values to translate.
First huge difference is size of matrix, flash use 4x5 matrix while IM want 5x5, maybe someone will help and explain something about that mysterious 5th row ?
Secondly, flash matrix values (ay least 5th column) are not normalized between 0 and 1. They could sometimes be bigger.
Re: Edit image in Flash and Using Imagemagick at backend
Posted: 2010-03-26T11:50:05-07:00
by magick
The recolor matrix is set up like this in ImageMagick:
- dstR = a[0] * srcR + a[1] * srcG + a[2] * srcB + a[3] * srcA + a[20]
dstG = a[5] * srcR + a[6] * srcG + a[7] * srcB + a[8] * srcA + a[21]
dstB = a[10] * srcR + a[11] * srcG + a[12] * srcB + a[13] * srcA + a[22]
dstA = a[15] * srcR + a[16] * srcG + a[17] * srcB + a[18] * srcA + a[23]
Re: Edit image in Flash and Using Imagemagick at backend
Posted: 2010-03-28T15:47:40-07:00
by anthony
xtonic wrote:
while IM docu also doesnt say very much:
RecolorImage() translate, scale, shear, or rotate image colors. Although you can use variable sized matrices, typically you use a 5 x 5 for an RGBA image and a 6x6 for CMYKA. Populate the last row with normalized values to translate.
See IM Examples...
http://www.imagemagick.org/Usage/color/#recolor
yes it is just raw notes, but it basically explains the option.
The matrix can be 3x3 4x4 or 5x5 depending on if you are modifying a 3, 4, ot 5 channel image.
For example RGB or RGBA, or CMYKA respectively.
Re: Edit image in Flash and Using Imagemagick at backend
Posted: 2010-03-29T00:38:24-07:00
by xtonic
Any hint how to convert from flash matrix ? Maybe values should be normalized ?
Flash uses 4x5 matrix and RGBA, the 5th column is offset. I tried magick's formula
to convert the matrix, but it didnt worked, resulting image is still in acid colors.
magic's formula says that elements a[4], a[9], a[14], a[19] are not used in calculation
and therefore do not affect resulting image, but testing shows that they DO affect resulting image.
Thanks for reply.
Re: Edit image in Flash and Using Imagemagick at backend
Posted: 2010-03-29T06:51:50-07:00
by magick
Can you post a URL to an image, the Flash matrix you use and a URL to the results. We'll download it and see if we can reproduce the problem. If we get the acid colors we will look toward a patch to fix the problem.
Re: Edit image in Flash and Using Imagemagick at backend
Posted: 2010-03-29T17:24:41-07:00
by anthony
xtonic wrote:Any hint how to convert from flash matrix ? Maybe values should be normalized ?
Flash uses 4x5 matrix and RGBA, the 5th column is offset.
First you said 5 column. that would make it a 5x4 matrix (remember X or coumns) are always first!
The ImageMagick re-color matrix (4x4) should then be the same as a transposed flash matrix
but without the last column (offset). It would treat that column as being a column of zeros.
Of course without someone experimenting to confirm this, it is speculation on my part, but that is what it sounds like. See the notes in the link I gave above. It explains how the matrix gets converted into color modifications.
Cristy DO NOT patch -recolor matrix. It is working correctly as defined!
Re: Edit image in Flash and Using Imagemagick at backend
Posted: 2010-03-30T00:09:04-07:00
by xtonic
Hello again.
I'm testing it on following example:
http://www.emanueleferonato.com/2009/04 ... ter-class/
Lets pick "Adding contrast" matrix, which is:
Code: Select all
1.50 0.00 0.00 0.00 -40.00
0.00 1.50 0.00 0.00 -40.00
0.00 0.00 1.50 0.00 -40.00
0.00 0.00 0.00 1.00 0.00
After converting it to magick matrix by magic's formula, i got this:
Code: Select all
1.50 0.00 0.00 0.00 -40.00
0.00 1.50 0.00 0.00 -40.00
0.00 0.00 1.50 0.00 -40.00
0.00 0.00 0.00 1.00 0.00
-40.00 -40.00 -40.00 0.00 0.00
0.00 0.00 0.00 0.00 0.00
Now its time to apply it with perl script:
Code: Select all
#!/usr/local/bin/perl
use Image::Magick;
$image = Image::Magick->new;
$x = $image->Read('http://www.emanueleferonato.com/images/cats.jpg');
$image->Recolor([qw(
1.50 0.00 0.00 0.00 -40.00
0.00 1.50 0.00 0.00 -40.00
0.00 0.00 1.50 0.00 -40.00
0.00 0.00 0.00 1.00 0.00
-40.00 -40.00 -40.00 0.00 0.00
0.00 0.00 0.00 0.00 0.00)]);
$image->Write('result.jpg');
And voila! The black square

Re: Edit image in Flash and Using Imagemagick at backend
Posted: 2010-03-30T11:30:54-07:00
by magick
ImageMagick can be built at depths of 8, 16, or 32 so must use normalized values. Your command should look like this:
- convert cats.jpg -recolor \
" 1.50 0.00 0.00 0.00 \
0.00 1.50 0.00 0.00 \
0.00 0.00 1.50 0.00 \
-0.16 -0.16 -0.16 1.00" mycats.jpg
Re: Edit image in Flash and Using Imagemagick at backend
Posted: 2010-03-30T16:48:41-07:00
by xtonic
Sorry my abuse, but what is better solution ? Recompile with 32 bits ? Then normalization will not be required ?
Which range one should normalize ? 0..255 ? Im asking this annoying questions because result is now close, but still
do not match flash version. Thanks for your patience and good work.