Getting info:- out of -trim and deskew

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
aporthog
Posts: 37
Joined: 2012-05-30T08:24:46-07:00
Authentication code: 13

Getting info:- out of -trim and deskew

Post by aporthog »

I want to get the final geometry of an image that has been trimmed and deskewed for use in another program but I can't figure out how to do it. I read this but don't understand the output I am seeing:

http://www.imagemagick.org/Usage/crop/#trim

This documentation tells how to get information out of -trim but doesn't interpret it.

Code: Select all

convert out2.tif -bordercolor black -border 1x1 -fuzz 88% -trim info:-

out2.tif TIFF 1668x2715 1776x2969+1+113 8-bit sRGB 0.047u 0:00.017
1668x2715 is the final dimensions of the image. What exactly is 1776x2969+1+113? The documentation says it refers to the part that has been trimmed but I have no idea how to interpret that.

What I want to do is get the final geometry of an image after a series of operations. This will happen inside a program so doesn't have to be in a single IM command, but that's always nice if it's possible.

This is the initial image:

Image

After the series of operations I want to get a [w]x[h]+dx+dy coordinates and a rotation with respect to the original.

The first operation is a known initial crop value:

Code: Select all

convert input.tif -crop 1774x2967+336+1491 output.tif
Image

The second operation I tack on is a deskew:

Code: Select all

convert input.tif -crop 1774x2967+336+1491 -background black -deskew 60% output.tif
Image

The last operation is the -trim:

Code: Select all

convert input.tif -crop 1774x2967+336+1491 -background black -deskew 60% -bordercolor black -border 1x1 -fuzz 88% -trim output.tif
Image

So what I want to end up with is the deskew angle to slightly rotate the inital image and the [w]x[h]+dx+dy coordinates of the final image within the original image. I know how to get the deskew angle by putting -print %[deskew:angle] null: at the end of my command, but I'm not sure how to combine that with the other information I need.

Any ideas? The original tiff image is here: http://ucblibrary4.berkeley.edu/~apollo ... /input.tif
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Getting info:- out of -trim and deskew

Post by fmw42 »

Add +repage, unless you want to know where the result would be offset from the padded image.

Code: Select all

convert out2.tif -bordercolor black -border 1x1 -fuzz 88% -trim +repage info:

Also see

http://www.imagemagick.org/script/escape.php

Code: Select all

convert out2.tif -bordercolor black -border 1x1 -fuzz 88% -trim +repage -format "%O  %P" info:
or

Code: Select all

convert out2.tif -bordercolor black -border 1x1 -fuzz 88% -format "%@" info:
If those fail, then redirect std err to std out by adding at the end 2>&1
Post Reply