Crop coordinates to text file
Crop coordinates to text file
Hi. I'm using Imagemagik for Windows. I need to resize and crop several images so I've created a batch file. The resulting images are perfect, but I'm wondering if there is any way to get the x1,y1,x2,y2 coordinates of each crop. I'm using -gravity center so what I need is to log to a text file the coordinates of each file croped. Any help will be most appreciated! thank you!
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Crop coordinates to text file
See %@ string format at http://www.imagemagick.org/script/escape.php
convert image -format "%@" info:
gives the crop arguments without having to crop the image.
Alternately, crop the imaged but do not add +repage. Then get the crop arguments from %O and %wx%h.
You will have to use fx calculations to convert ul coordinates and size to ul and br coordinates.
Please always provide your IM version when asking questions.
convert image -format "%@" info:
gives the crop arguments without having to crop the image.
Alternately, crop the imaged but do not add +repage. Then get the crop arguments from %O and %wx%h.
You will have to use fx calculations to convert ul coordinates and size to ul and br coordinates.
Please always provide your IM version when asking questions.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Crop coordinates to text file
I think the OP is using "-gravity center -crop..." rather than "-trim", like this (Windows BAT syntax):
Code: Select all
convert ^
in.png ^
-gravity center -crop 100x100+0+0 ^
-format "%%w %%h %%O" +write info: ^
+repage ^
out.png >>logfile.txt
snibgo's IM pages: im.snibgo.com
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: Crop coordinates to text file
In order to append that information to "logfile.txt" I have to put a newline "\n" in the formatting operator. Otherwise it just keeps adding the new information to the existing line. Also some other information might be helpful in the log, like the name of the original file, and maybe its size before cropping. That could easily be done with a little tweak to your suggestion using the "%f" to provide the file name and the "%G" to provide the pre-crop dimensions, something like this...snibgo wrote:I think the OP is using "-gravity center -crop..." rather than "-trim", like this (Windows BAT syntax):
Code: Select all
convert ^ in.png ^ -gravity center -crop 100x100+0+0 ^ -format "%%w %%h %%O" +write info: ^ +repage ^ out.png >>logfile.txt
Code: Select all
...
-format "%f: %G %O %w %h\n" +write info: ^
...
Re: Crop coordinates to text file
Thank you very much for your help, I really appreciate it.