image proerties as arguments

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

image proerties as arguments

Post by GreenKoopa »

I would like to set every pixel in an entire image to the image's maximum (or minimum, etc.) value. I tried:

convert -size 100x256 gradient:#000-#999 in.png
convert in.png -evaluate Set %[fx:maxima] out.png
convert in.png -format %[fx:maxima] info: --- 0.6
convert out.png -format %[fx:maxima] info: --- 0

No error, just a solid black output.

If some of my image is fully transparent, will those values be ignored or will I need to set them to black with -alpha Background?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: image proerties as arguments

Post by fmw42 »

I am not expert on this, but I don't know if -evaluate set honors %[fx...]. You probably need to get the max value and put it into a variable and then use that to change the image

max=`convert image -format "%[fx:100*maxima]" info:`
convert image -fill "gray($max%)" -colorize 100% result
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: image proerties as arguments

Post by GreenKoopa »

I have tried using %[max]. I have also tried a -set option: arrangement.

The solution wouldn't have to involve -evaluate, it was just the only idea I had.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: image proerties as arguments

Post by fmw42 »

GreenKoopa wrote:I have tried using %[max]. I have also tried a -set option: arrangement.

The solution wouldn't have to involve -evaluate, it was just the only idea I had.

Perhaps you missed my solution right above your note. Seems like we submitted at about the same time.

max=`convert image -format "%[fx:100*maxima]" info:`
convert image -fill "gray($max%)" -colorize 100% result
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: image proerties as arguments

Post by GreenKoopa »

Thank you, scripting outside of IM is certainly one solution. -fx maxima is one too (but very slow). My original try didn't give an error so I just wondered if I was close. My try did result in some unexpected behavior, so my curiosity increased.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: image proerties as arguments

Post by anthony »

At this time only very specific options allow you to specify arguments using escape sequences.

These include...
-set
-annotate
-distort
-sparse-color
-format, -label, -caption & -comment (though really they store the string for later expansion)

However most options do NOT. They either take a 'geometry' string, or color value.

Remember both 'geometry' and 'color' strings could include '%' in them, and those percents must NOT be expanded as being percent escapes.

proposal


One proposed solution is that percent escapes must not have a digit before it unless followed by a '[' or '%'. As such these are not percent escaped...

100%x30 rgb(100%,100%,100%,.5)

But these are expanded as percent escapes...

100%% %wx%h max=%[maximum]

That is the first escapes the percent shrinking it to one percent, the others do not have a digit before it

If this proposal can be done, then there is no reason why ALL option arguments could not have percent escapes.

THE EXCEPTION to this is -define -label -caption -comment, which much store the given string, including all percent escapes for later expansion when the saved value is actually used with an actual image.

see older raw notes on this type of problem in
http://www.imagemagick.org/Usage/bugs/future/#settings
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: image proerties as arguments

Post by GreenKoopa »

Good proposal! More functionality but no added complexity for the user who doesn't need it.

Probably can't be done for historical compatibly reasons, but I propose that the % symbol never be used. Countless hours have been wasted by us outcast Windows users. :(
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: image proerties as arguments

Post by anthony »

It was before my time (way before) but % I belied was picked originally because it was not $ whcih was already heavily used by shells, perl, and PHP. :?

It just happened that % was used by DOS! :(

If you are feeling down trodden, you could always install CgiWin and get a BASH shell on a windows box :lol:
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: image proerties as arguments

Post by GreenKoopa »

anthony wrote: If you are feeling down trodden, you could always install CgiWin and get a BASH shell on a windows box :lol:
I should know more of linux. I know a bit of Perl, but then I change Windows machines and it's not available. Or I could learn VBScript or Windows PowerShell. My curiosity exceeds my time and talent. :(
Post Reply