Page 1 of 1

drawing crop lines from micrometer

Posted: 2010-05-31T05:54:17-07:00
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

Re: drawing crop lines from micrometer

Posted: 2010-05-31T07:03:02-07:00
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.

Re: drawing crop lines from micrometer

Posted: 2010-05-31T08:56:07-07:00
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

Re: drawing crop lines from micrometer

Posted: 2010-05-31T09:06:31-07:00
by Bonzo

Code: Select all

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

Re: drawing crop lines from micrometer

Posted: 2010-05-31T09:09:20-07:00
by borell
Thanks !!
That was it

Re: drawing crop lines from micrometer

Posted: 2010-05-31T09:37:36-07:00
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 !

Re: drawing crop lines from micrometer

Posted: 2010-06-16T06:32:22-07:00
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

Re: drawing crop lines from micrometer

Posted: 2010-06-16T10:39:44-07:00
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

Re: drawing crop lines from micrometer

Posted: 2010-06-16T11:50:59-07:00
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 ?

Re: drawing crop lines from micrometer

Posted: 2010-06-16T13:30:45-07:00
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.

Re: drawing crop lines from micrometer

Posted: 2010-06-17T06:06:02-07:00
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

Re: drawing crop lines from micrometer

Posted: 2010-06-17T06:20:20-07:00
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".

Re: drawing crop lines from micrometer

Posted: 2010-06-17T21:28:47-07:00
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.