Hi,
is there an automatic (e.g. without external calculation) way to accomplish the following:
=> crop a quadrant from the centre of an image whose side = 1.1*min(image_width, image_height); with black border needed wherever required.
Semantically it would be equivalent to the following not-so-optimal operations:
(1) add black border on both sides at the smaller dimension; border sickness >= 0.1*min(image_width, image_height)
(2) crop the quadrant from the image with border; size = 1.1*min(image_width, image_height)
But as usual with ImageMagick, there could be an elegant one-line solution that doesn't create huge intermediate images.
Thank you in advance,
Oleg.
How to crop a quadrant out of an image
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: How to crop a quadrant out of an image
What version IM? What platform?
What do you mean by "quadrant"? This normally means a quarter, but you mean something else?
What do you mean by "quadrant"? This normally means a quarter, but you mean something else?
snibgo's IM pages: im.snibgo.com
Re: How to crop a quadrant out of an image
Sorry for the confusion; I meant a square - a sub-image with horizontal and vertical dimensions being equal.
Regarding the IM version, I'd assume the latest one. My platform is MS Windows for now, though portability would be nice.
Thanks again,
Oleg.
Regarding the IM version, I'd assume the latest one. My platform is MS Windows for now, though portability would be nice.
Thanks again,
Oleg.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: How to crop a quadrant out of an image
This does what I think you want. Windows BAT syntax.
Tested in v6.9.5-3 (using "convert" instead of "magick") and v7.0.3-5.
Code: Select all
magick ^
in.png ^
-virtual-pixel Black ^
-set option:distort:viewport ^
%%[fx:1.1*min(w,h)]x%%[fx:1.1*min(w,h)]+%%[fx:(w-1.1*min(w,h))/2]+%%[fx:(h-1.1*min(w,h))/2] ^
-filter Point -distort SRT 1,0 ^
+repage ^
out.png
snibgo's IM pages: im.snibgo.com
Re: How to crop a quadrant out of an image
Thanks for your effort Mr snibgo, but ... it doesn't work - the resulting images have the same size as the inputs.
I pasted the command into DOS window:
---->set CONVERT="C:\Program Files (x86)\ImageMagick-7.0.5-5-portable-Q16-x86\convert.exe"
---->for %f in (*.TIF) DO %CONVERT% %f ^
More? -virtual-pixel Black ^
More? -set option:distort:viewport ^
More? %[fx:1.1*min(w,h)]x%%[fx:1.1*min(w,h)]+%[fx:(w-1.1*min(w,h))/2]+%[fx:(h-1.1*min(w,h))/2] ^
More? -filter Point -distort SRT 1,0 ^
More? +repage ^
More? -compress LZW SQUARE\%~nf.TIF
---->"C:\Program Files (x86)\ImageMagick-7.0.5-5-portable-Q16-x86\convert.exe" DSC00003-00009_l.TIF -virtual-pixel Black -set option:distort:viewport %[fx:1.1*min(w,h)]x%%[fx:1.1*min(w,h)]+%[fx:(w-1.1*min(w,h))/2]+%[fx:(h-1.1*min(w,h))/2] -filter Point -distort SRT 1,0 +repage -compress LZW SQUARE\DSC00003-00009_l.TIF
---->"C:\Program Files (x86)\ImageMagick-7.0.5-5-portable-Q16-x86\convert.exe" DSC00004-00010_l.TIF -virtual-pixel Black -set option:distort:viewport %[fx:1.1*min(w,h)]x%%[fx:1.1*min(w,h)]+%[fx:(w-1.1*min(w,h))/2]+%[fx:(h-1.1*min(w,h))/2] -filter Point -distort SRT 1,0 +repage -compress LZW SQUARE\DSC00004-00010_l.TIF
I pasted the command into DOS window:
---->set CONVERT="C:\Program Files (x86)\ImageMagick-7.0.5-5-portable-Q16-x86\convert.exe"
---->for %f in (*.TIF) DO %CONVERT% %f ^
More? -virtual-pixel Black ^
More? -set option:distort:viewport ^
More? %[fx:1.1*min(w,h)]x%%[fx:1.1*min(w,h)]+%[fx:(w-1.1*min(w,h))/2]+%[fx:(h-1.1*min(w,h))/2] ^
More? -filter Point -distort SRT 1,0 ^
More? +repage ^
More? -compress LZW SQUARE\%~nf.TIF
---->"C:\Program Files (x86)\ImageMagick-7.0.5-5-portable-Q16-x86\convert.exe" DSC00003-00009_l.TIF -virtual-pixel Black -set option:distort:viewport %[fx:1.1*min(w,h)]x%%[fx:1.1*min(w,h)]+%[fx:(w-1.1*min(w,h))/2]+%[fx:(h-1.1*min(w,h))/2] -filter Point -distort SRT 1,0 +repage -compress LZW SQUARE\DSC00003-00009_l.TIF
---->"C:\Program Files (x86)\ImageMagick-7.0.5-5-portable-Q16-x86\convert.exe" DSC00004-00010_l.TIF -virtual-pixel Black -set option:distort:viewport %[fx:1.1*min(w,h)]x%%[fx:1.1*min(w,h)]+%[fx:(w-1.1*min(w,h))/2]+%[fx:(h-1.1*min(w,h))/2] -filter Point -distort SRT 1,0 +repage -compress LZW SQUARE\DSC00004-00010_l.TIF
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: How to crop a quadrant out of an image
As I said, my code is Windows BAT syntax. For Windows CMD, change each double %% to single %.
snibgo's IM pages: im.snibgo.com
Re: How to crop a quadrant out of an image
You are right! I forgot to replace one instance of %%.
Now it works for me.
Thanks a lot!
Oleg.
Now it works for me.
Thanks a lot!
Oleg.