Page 1 of 1

How to work with FX in Magick++?

Posted: 2017-04-20T16:13:21-07:00
by Airon65
According to this article: https://www.imagemagick.org/script/fx.php and also this article: https://www.imagemagick.org/Usage/trans ... ex.html#fx I started with the simplest code which using FX-feature of IM:

Code: Select all

Magick::Image testImg( Magick::Geometry( 500, 500 ), Magick::Color( QuantumRange, QuantumRange, QuantumRange, QuantumRange ) );
testImg.fx( "i/w" );
testImg.write( "images/test-img.png" );
And it didn't work :) Looks like I should specify the channel with which I'm working. Ok I write the next attempt of code:

Code: Select all

Magick::Image testImg( Magick::Geometry( 500, 500 ), Magick::Color( QuantumRange, QuantumRange, QuantumRange, QuantumRange ) );
testImg.fx( "rgba( 255, i/2, i/2, 255 )" );
testImg.write( "images/test-img.png" );
but the result image is black. Looks like "i"-variable cannot be used inside the rgb/rgba function, isn't it? I'm just trying to create any gradient :)

How to work with channels using FX-feature? How to specify it or something like this...?

Re: How to work with FX in Magick++?

Posted: 2017-04-21T05:20:03-07:00
by snibgo
Please, always state what version of IM you are using.

img.fx("i/w") works fine for me (IM v7.0.1-0). If you need help, I suggest you expand "And it didn't work". What didn't work? What was the output?

I suggest you also show a complete (but minimal) program.

Re: How to work with FX in Magick++?

Posted: 2017-04-21T06:26:15-07:00
by Airon65
Ok! I forgot to put my IM's version here, sorry.
I use: ImageMagick 7.0.5-2 Q16 x86_64 2017-03-11, macOS 10.12.3

Code:

Code: Select all

Magick::InitializeMagick( *argv );
Magick::Image testImg( Magick::Geometry( 500, 500 ), Magick::Color( "white" ) );
testImg.fx( "i/w" );
testImg.write( "images/test-img.png" );
gives me broken png file. It doesn't even open in the viewer. The same result for: testImg.fx( "i/2" );

Re: How to work with FX in Magick++?

Posted: 2017-04-21T06:32:10-07:00
by snibgo
That isn't a complete program.

By "complete program" I mean something I can paste into a file, so I can build and run it.

Re: How to work with FX in Magick++?

Posted: 2017-04-21T06:38:08-07:00
by Airon65

Code: Select all

#include <iostream>		
#include <Magick++.h>
		
int main( int argc, char **argv ) {
 
	Magick::InitializeMagick( *argv );
	
	Magick::Image testImg( Magick::Geometry( 500, 500 ), Magick::Color( "white" ) );
	testImg.fx( "i/2" );
	testImg.write( "images/test-img.png" );				

	return 0;				
	
}
Build line:

Code: Select all

g++ ./test.o -std=c++14 Test.cpp `Magick++-config --cppflags --cxxflags --ldflags --libs`

Re: How to work with FX in Magick++?

Posted: 2017-04-21T06:47:39-07:00
by snibgo
After removing the directory, your program works fine for me (with very old v7.0.1-0). The result is opaque white except for column 0 which is rgba(0,0,0,0) and column 1 which is rgba(50%,50%,50%,0.5).

Re: How to work with FX in Magick++?

Posted: 2017-04-21T07:18:15-07:00
by Airon65
Well.. I opened result file with the Photoshop but it can't be open with the standart macos viewer. I've just rebooted my computer but it still doesn't open. With the Photoshop I see only the first column painted with a black color and the other ones is painted with white color.
I thought it should be painted with some gradient color but it's not. Why? :)

Re: How to work with FX in Magick++?

Posted: 2017-04-21T07:42:49-07:00
by Airon65
This line:

Code: Select all

testImg.fx( "200" );
also leads to the broken image. In my case this only one line which is worked for me:

Code: Select all

testImg.fx( "rgb(255,255,0)" );
in this case I see a yellow image.

Re: How to work with FX in Magick++?

Posted: 2017-04-21T08:00:49-07:00
by snibgo
I suggest you upload the broken PNG file so someone can take a look.

I don't know what you expect from...

Code: Select all

testImg.fx( "200" );
...because the number is outside the range 0.0 to 1.0.

Re: How to work with FX in Magick++?

Posted: 2017-04-21T08:04:39-07:00
by Airon65
snibgo wrote: 2017-04-21T08:00:49-07:00 I suggest you upload the broken PNG file so someone can take a look.
Sure. This my broken png file: https://ufile.io/vv7ya

Code:

Code: Select all

Magick::Image testImg( Magick::Geometry( 500, 500 ), Magick::Color( "white" ) );
testImg.fx( "i/w" );
testImg.write( "images/test-img.png" );
I don't know what you expect from...

Code: Select all

testImg.fx( "200" );
...because the number is outside the range 0.0 to 1.0.
Oops my fault :)

Re: How to work with FX in Magick++?

Posted: 2017-04-21T09:24:25-07:00
by snibgo
IM and Windows Photo Viewer can read vv7ya-test-img.png with no problem. What makes you think it is broken?

Re: How to work with FX in Magick++?

Posted: 2017-04-21T18:44:49-07:00
by Airon65
I've just updated my IM to 7.0.5-4 (previously I used 7.0.5-2) and now I see the code:

Code: Select all

Magick::Image testImg( Magick::Geometry( 500, 500 ), Magick::Color( "white" ) );
testImg.fx( "i/w" );
testImg.write( "images/test-img.png" );
generates a vertical gradient from black to white (from left to right). Not just one black vertical line as it was with some previous version of IM (I mean ...-2 version).
What makes you think it is broken?
This file cannot be viewed with the macOS viewer. Now with the 7.0.5-4 the problem almost solved. Now I can see the picture when I open it but there's some problem with the generating a thumbnail (preview). It looks like this:

Image

All those files were generated and saved with Magick's: img.write( "file.png" ) function. And the problem only with that "FX"-file.

Re: How to work with FX in Magick++?

Posted: 2017-04-21T18:46:41-07:00
by Airon65
If I use just:

Code: Select all

testImg.fx( "rgb(255,255,0)" );
I see the generated thumbnail (yellow background) for that file in my OS.