GeeMack wrote: ↑2018-04-19T07:29:32-07:00
muccigrosso wrote: ↑2018-04-19T06:47:34-07:00I'm saving an image height with `-set ht '%h'` and then using it later when I need to restore the image to its original height. What I tried to do was to add a border to the image where the height of the border is the difference between the original height and the current height. So I was hoping I could do something like `%[fx:ht-h]` but that doesn't work.
You can set variables that way, but you can't use them inside following FX expressions. There are, however, several ways to carry that value along and use it later in the command. If you can provide a simple example of a complete command or a more detailed description of what you're trying to accomplish, someone can surely offer suggestions about how to do that.
I'm doing this in a bash script on a Mac, so I can definitely get the value and save it, but I was hoping for a way that let me keep as much as possible in one IM command without having to write out a temp file. I enjoy trying to work through the code, which is why I limited my question to the ability to do math with variables (options?). However for a simplified version of what I'm doing more broadly, there's this:
Code: Select all
magick "$file" -set ht '%h' -gravity north -trim -fill black -draw 'color 0,0 reset' -background white -extent x"%[ht]"
There's more going on in my command, but it's that bit at the end that I'd like to do by adding a border instead of using extent, as here. I'm basically trimming down a file, making it black and then adding a white border on the top, so I need to know how big the border should be, hence the desire to somehow calculate the difference between the original height (assigned to ht) and the current height (which would be h, of course). The resultant file with be composited with the original.
In my much longer command, if I use extent to get the bigger image the entire resulting image is white, instead of retaining the black, so something else is going on there which leads me to try border.
PS In this simplified command, I get a white border on the left of the final image, in addition to the strip at top. I'm not sure why that's happening either.
Version: ImageMagick 7.0.7-28 Q16 x86_64 2018-03-26
http://www.imagemagick.org
Also, when you set a variable the way you've done, "-set ht '%h'", it will fail if you set it inside parentheses and try to access it outside the parentheses, or vice versa. A generally more useful way to set a variable is "-set option:ht '%h'". That way you can access it with "%[ht]" anywhere later in the command.
Thanks for this.