How to use fximage in PHP?

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
mjamal
Posts: 62
Joined: 2017-12-27T06:13:59-07:00
Authentication code: 1152

How to use fximage in PHP?

Post by mjamal »

How can I use the below line of code in PHP imagick?

convert -channel green input.jpg -fx "u*42/255" out.jpg

Please let me know. Thanks in advance.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to use fximage in PHP?

Post by fmw42 »

That code is not valid. -fx is not -channel sensitive. It should be

Code: Select all

convert input.jpg -fx "u.g*42/255" out.jpg
For Imagick, see http://us3.php.net/manual/en/imagick.fximage.php
mjamal
Posts: 62
Joined: 2017-12-27T06:13:59-07:00
Authentication code: 1152

Re: How to use fximage in PHP?

Post by mjamal »

Hello Fmw42,

Thank you for your quick response. Can you please let me know how can i use imagick fximage expression for the changing the Curves values of Output = 160 and Input = 130 for any image, please see the attached screen shot for your reference and please provide the imagick fximage expression or any other function from which I can do that for the same changes.

Thanks in advanced.
Attachments
Change Output = 160 and Input = 130
Change Output = 160 and Input = 130
curves.png (35.2 KiB) Viewed 22175 times
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to use fximage in PHP?

Post by fmw42 »

Neither Imagemagick nor Imagick have a curves function like that. -fx can be used to create a curve if you know the mathematical formula. The closest thing in Imagemagick is either -gamma or -evaluate pow or -evaluate log. Imagick should have equivalent functions.

See
http://www.imagemagick.org/Usage/transform/#fx
http://www.imagemagick.org/Usage/color_ ... evel_gamma
http://www.imagemagick.org/Usage/color_mods/#non-linear
http://www.imagemagick.org/Usage/color_mods/#curves
http://www.imagemagick.org/script/comma ... p#evaluate

Or if on Unix-like systems, you can use one of my scripts via PHP exec(). See my scripts, curves or kneemap at my link below. Kneemap shows comparison curve graphs for -evaluate pow (-gamma), -evaluate log and kneemap.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to use fximage in PHP?

Post by fmw42 »

mjamal
Posts: 62
Joined: 2017-12-27T06:13:59-07:00
Authentication code: 1152

Re: How to use fximage in PHP?

Post by mjamal »

Thanks again for quick response.

I am using the PHP scripting language for converting the photoshop curves values as mentioned earlier. Also I didn't know the mathematical formula for changing the same with -fx but I think the fximage will works exactly same as photoshop curves, please suggest.

Also please let me know if Gamma or Evaluate Imagick function will solve my problem?

Thanks in advanced.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to use fximage in PHP?

Post by fmw42 »

You can draw a polynomial function using control point using -fx, as per http://www.imagemagick.org/Usage/color_mods/#curves. But it is not the easiest way. If all you want is a slight curve such as in your diagram, you can do that with -evaluate pow X. That would be the easiest way in Imagick.

Sorry, I do not know to what extent you are doing
I am using the PHP scripting language for converting the photoshop curves values as mentioned earlier.
Converting them into what?
mjamal
Posts: 62
Joined: 2017-12-27T06:13:59-07:00
Authentication code: 1152

Re: How to use fximage in PHP?

Post by mjamal »

Hello Fred,

Thank you. I will check the Imagick -evaluate pow X to do the changes in image same as photoshop curves did.
Also I am using PHP language for using the photoshop features in website using the Imagick functions.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to use fximage in PHP?

Post by snibgo »

mjamal wrote:Can you please let me know how can i use imagick fximage expression for the changing the Curves values of Output = 160 and Input = 130 for any image
This can be done with power curve, out = in ^ p, where...

p = log (y) / log(x)

... where x is the required input and y is the output, both in the range 0.0 to 1.0.

In your case, y=160/255 and x=130/255, so p is 0.69180585.

Code: Select all

convert in.png -evaluate Pow 0.69180585 out.png
This can be done with "-fx", but this is massively slow for large images.

Sorry, I don't know IMagick.
snibgo's IM pages: im.snibgo.com
mjamal
Posts: 62
Joined: 2017-12-27T06:13:59-07:00
Authentication code: 1152

Re: How to use fximage in PHP?

Post by mjamal »

Thanks snibgo,

I am trying with the "-evaluate Pow 0.69180585" in Imagick but it is not providing the exact result which we are getting from photoshop. I am using the below line of code for converting the same.

$imagick->evaluateimage(Imagick::EVALUATE_POW, 0.69180585, imagick::CHANNEL_ALL);

Still investigating for the exact result.

BTW Thanks for your valuable feedback.
mjamal
Posts: 62
Joined: 2017-12-27T06:13:59-07:00
Authentication code: 1152

Re: How to use fximage in PHP?

Post by mjamal »

Also is there any other was I can change the photoshop CURVES output & input values from image magick functions?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to use fximage in PHP?

Post by snibgo »

mjamal wrote:... but it is not providing the exact result which we are getting from photoshop.
If you show us the input image and the two outputs, perhaps we can suggest the reason.
mjamal wrote:Also is there any other was I can change the photoshop CURVES output & input values from image magick functions?
There are many ways of applying transformation curves in ImageMagick. See the links supplied by fmw42. My own pages describe various methods.

Photoshop is an interactive editor, so you can tweak the curve and judge the effect. My pages describe how to automatically collect information about the image, and generate the curve that has a required effect.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to use fximage in PHP?

Post by fmw42 »

If you have one specific set of points on the photoshop Curves. You can create a HALD CLUT image in Imagemagick. Then apply the same points to that image in Photoshop to capture the exact Photoshop curve. Then bring that result back to Imagemagick and use -hald-clut to apply it to any image. Do not save the HALD image as JPG or any lossless compressed image.

See http://www.imagemagick.org/Usage/color_mods/#hald-clut

I do not know if Imagick supports half-clut command.

You can also do the same with a gradient image and just us -clut.

See http://www.imagemagick.org/Usage/color_mods/#color_lut
Post Reply