drawing crop lines from micrometer

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
borell

drawing crop lines from micrometer

Post by borell »

I have a program where I can intercept the jpg image and associated XML which contains the crop information. The xml has the following information;

a) Vertical offset from UL corner
b) Horizontal offset from UL corner
c) Rotation
d) Crop Height
e) Crop Width
f) all above in micrometer

My goal is to;

1) send two images; original size and 800 pixels on its longest side
2) draw a rectangle basically displaying the crop outline(but not crop the image)

I first divided the micrometer by 25,400 and then by by .003334 to get pixels. At that point I'm not sure of the command to draw the four lines and also what would be the command(or division) for the second image. If I could get the first image with the rectangle drawn, I could just resize that.

Any help much appreciated,
Frank
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: drawing crop lines from micrometer

Post by Bonzo »

See http://www.imagemagick.org/script/comma ... s.php#draw to create the rectangle.

As you do not say how you are running the command line code it is hard to make any further suggestions about calculations etc.
borell

Re: drawing crop lines from micrometer

Post by borell »

Thanks -I'm a little closer.

running: convert -draw "rectangle 50,50,300,700" image1 image2

-adds a black rectangle in the upper left hand quadrant. I tried -fill none in different areas of the line - but no luck. Also -stroke 2 and strokewidth 2 -still no luck.

How might I add just a 1 or two pixel outline?
-fb
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: drawing crop lines from micrometer

Post by Bonzo »

Code: Select all

convert image1 -stroke black strokewidth 1 -fill none -draw "rectangle 50,50,300,700" image2
borell

Re: drawing crop lines from micrometer

Post by borell »

Thanks !!
That was it
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: drawing crop lines from micrometer

Post by Bonzo »

I am glad it worked; you can see some examples of how to use the operators together on my site: http://www.rubblewebs.co.uk/imagemagick/operator.php
The examples use php but you should be able to modify it to what you need. The pages are also quite large !
borell

Re: drawing crop lines from micrometer

Post by borell »

Is it possible to rotate the rectangle(s) say 45 degrees - but not the image ?

The current command is;
convert -auto-orient source_file -stroke white -strokewidth 4 -fill none -draw "rectangle 1477.42204724,385.683464567,2477.42204724,985.683464567" -stroke black -strokewidth 2 -fill none -draw "rectangle 1471.42204724,379.683464567,2483.42204724,991.683464567" -interlace none -resize 800x532 destination_file

Thanks,
Frank
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: drawing crop lines from micrometer

Post by fmw42 »

try this test case:

convert -size 200x200 xc:lightblue -fill white -stroke black -strokewidth 1 \
-draw 'translate 100,100 rotate 30 rectangle -50,-50 50,50' tmp.png
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: drawing crop lines from micrometer

Post by Bonzo »

Your code will create a rectangle on the image:

Code: Select all

//translate center position x center position y rotate angle rectangle -width of side from center,-height of side from center +width of side from center,+height of side from center
exec("convert -auto-orient small.jpg -stroke white -strokewidth 4 -fill none -draw \"translate 100,100 rotate 45 rectangle -50,-50 50,50\" -stroke black -strokewidth 2 -fill none -draw \"translate 100,100 rotate 45 rectangle -50,-50 50,50\" -interlace none -resize 800x532 tmp1.png");
I do not know how it will work for Frank or if he would be better of creating a tempory image and overlaying it? Eitherway getting the roataion point correct could be a problem ?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: drawing crop lines from micrometer

Post by fmw42 »

You could draw your rectangle on a transparent background, use distort SRT to rotate it about some point and then overlay it on the background image. Sorry I have not been following this thread much so don't understand what the issue may be or the goal.
borell

Re: drawing crop lines from micrometer

Post by borell »

I tried adding the "rotate 45" in front of rectangle;

C:\cci_pd>convert -auto-orient source_file -stroke white -strokewidth 4 -fill none -draw "rotate -45 rectangle x_offset,y_offset, x, y" -stroke black -strokewidth 2 -fill none -draw "rotate -45
rectangle (x_offset -6),(y_offset -6), (x + 6),( y + 6)" -interlace none -resize 800x532 destination_file

Instead of swiveling the box in place, it drew the a rectangle(at a 45 degree tilt) in the lower left hand corner. Without "degree" being added, the rectangle is in the upper middle.

Catch-up /Goal
The code that I'm intercepting, provides me with the offsets(crop distance from left and top), crop width and height, original size(width, height), dpi and rotation degrees. I just needed to draw the crop lines on the image(rectangle) which was accomplished - until I came upon some rotated crops. While definetely in the minority, I was curious on how i would accomplish given the data I intercepted. I will try some of the other suggestions as well. Thanks again for the help!

Frank
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: drawing crop lines from micrometer

Post by snibgo »

Instead of swiveling the box in place, it drew the a rectangle(at a 45 degree tilt) in the lower left hand corner.
You'll also need to "translate".
snibgo's IM pages: im.snibgo.com
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: drawing crop lines from micrometer

Post by anthony »

For draw canvas warping (translate rotate etc) see
Im examples, Drawing on images
http://www.imagemagick.org/Usage/draw/#transform

You basically translate the origin to the point of rotation, then rotate the coordinates.

Of course as the coordinates were translated they will then be set relative to the new 'origin', unless you add another translation.

That is you really want to do a translate X,Y rotate A translate -X,-Y

that last is the action that is actually applied to the coordiantes given first.



Brain Dump in progress the following may be muddled and a little off topic...

You can actually do both in a single affine matrix too, though it is harder to understand.
The translate and rotate MVG primative actually merge themselves together internally into a single
the affine matrix. So it really is just the same thing.

See IM examples Scripts "affine_distort" and "affine_rotate" in
http://www.imagemagick.org/Usage/

these scritps were created before the -distort operator was add to IM, but for Draw they are still completely valid.

Also see Affine Matrix Transforms (sub-page of Distort)
http://www.imagemagick.org/Usage/distorts/affine/
for more details on using affine coefficients.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply