A while back, I got some great help here understanding how to merge images.
I am on a simpler task now, which is to mask out pixels using a polygon, then crop that to a known rectangle.
I have this (runs as windows batch file) and it works, but does not crop as I did not tell it to yet:
"C:\Program Files\ImageMagick-7.0.5-Q8\magick.exe" ^
( "C:\Users\james\Desktop\Kir\granite.png" ^
( -size 128x128 xc:black -fill white -stroke white -draw "polygon 0,0 0,64 64,64 64,0" ) -alpha off -compose CopyOpacity -composite ^
) ^
-compose over -layers merge ^
"C:\Users\james\Desktop\Kir\Final.jpg"
I want to do this, but it does not work:
"C:\Program Files\ImageMagick-7.0.5-Q8\magick.exe" ^
( "C:\Users\james\Desktop\Kir\granite.png" ^
( -size 128x128 xc:black -fill white -stroke white -draw "polygon 0,0 0,64 64,64 64,0" ) -alpha off -compose CopyOpacity -composite ^
) ^
-compose over -layers merge ^
-crop 100x100+0+0 ^
"C:\Users\james\Desktop\Kir\Final.jpg"
I got close doing a couple other ways, but liked the merge method. Just not sure how to organize the code to crop it.
thanks
Mask using polygon, then crop to known coordinates
Mask using polygon, then crop to known coordinates
James Maeding
Civil Engineer / Programmer
Civil Engineer / Programmer
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Mask using polygon, then crop to known coordinates
What's wrong? Posting sample input and output images would help.jmaeding wrote:... but it does not work
snibgo's IM pages: im.snibgo.com
Re: Mask using polygon, then crop to known coordinates
Sorry, I should have said - it outputs 4 images...but.... I just retested my own code, the one in my post with the -crop, and it works now.
As I wrote the post, I added +0+0 to the crop statement just to be more explicit.
I had never tested that as I thought the default was no shift on crop rectangle.
Turns out that fixed it, it only makes one image and its correct.
I just rechecked the IM web page for -crop, and they never omit the +x+x part, my bad.
I have no idea why we get 4 images if that is not there, what does "64x64" parameter of crop mean without the +x+x?
As I wrote the post, I added +0+0 to the crop statement just to be more explicit.
I had never tested that as I thought the default was no shift on crop rectangle.
Turns out that fixed it, it only makes one image and its correct.
I just rechecked the IM web page for -crop, and they never omit the +x+x part, my bad.
I have no idea why we get 4 images if that is not there, what does "64x64" parameter of crop mean without the +x+x?
James Maeding
Civil Engineer / Programmer
Civil Engineer / Programmer
Re: Mask using polygon, then crop to known coordinates
Without the +x+x it creates as many images it can at the 64x64 dimension from the original.
https://www.imagemagick.org/script/comm ... s.php#crop
https://www.imagemagick.org/script/comm ... s.php#crop
If the x and y offsets are omitted, a set of tiles of the specified geometry, covering the entire input image, is generated. The rightmost tiles and the bottom tiles are smaller if the specified geometry extends beyond the dimensions of the input image.
Last edited by Bonzo on 2017-08-30T09:23:59-07:00, edited 1 time in total.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Mask using polygon, then crop to known coordinates
As Bonzo says. See the documentation http://www.imagemagick.org/script/comma ... s.php#crop:
+0+0 are the x and y offsets. Omit that, and you get a set of images.If the x and y offsets are omitted, a set of tiles of the specified geometry, covering the entire input image, is generated.
snibgo's IM pages: im.snibgo.com
Re: Mask using polygon, then crop to known coordinates
snibgo posted as I was editing my answer to add more detail.
Re: Mask using polygon, then crop to known coordinates
oh wow, I hit the Launch button instead of the Lunch button and ended up on the moon....(Far Out Space Nuts...)
That would have been funny if I was testing on some larger images.
That would have been funny if I was testing on some larger images.
James Maeding
Civil Engineer / Programmer
Civil Engineer / Programmer
Re: Mask using polygon, then crop to known coordinates
btw, I just noticed another issue that may have been fooling me in tests.
When you do a windows batch, and use ^ for line continuation, you must add a space at beginning of next line.
Programmers expect "white space" to be irrelevant, so that one bit me today pretty good.
When you do a windows batch, and use ^ for line continuation, you must add a space at beginning of next line.
Programmers expect "white space" to be irrelevant, so that one bit me today pretty good.
James Maeding
Civil Engineer / Programmer
Civil Engineer / Programmer
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Mask using polygon, then crop to known coordinates
Well, you need a space either at the start of the next line, or the end of the previous line (before the ^). The IM parser needs at least one space between elements.
snibgo's IM pages: im.snibgo.com