Page 1 of 1

Drawing a Six Inch Box

Posted: 2013-06-24T11:31:57-07:00
by nas
Hi everyone,
I'm new to ImageMagick, and photo manipulation in general, but I'm working on a project that requires me to draw a box that is six inches long, based on image resolution. The Windows photo viewer reports that the horizontal and vertical resolution of the image is 96dpi. So, would I simply use a draw command to draw a box that is 576 pixels long and then manually scale it until it's six inches so the size of the rest of the image can be judged off of that line? Here is the command I'm currently using, but it doesn't seem to work properly:

Code: Select all

convert.exe "C:\path\to\file\file.jpg" -strokewidth 5 -stroke black -fill white
		-draw "rectangle 0,0 20,576"
		"C:\path\to\file\output_file.jpg"
Thanks in advance for all help!

NAS

Re: Drawing a Six Inch Box

Posted: 2013-06-24T12:18:39-07:00
by fmw42
When you talk about inches, that only applies when printing. You can have any size image in pixels and can set the dpi correspondingly so that it prints to so many inches. You just have to set the -units and -density appropriately.

If your pixel size of the box is 576 and you want the box to print to 6 inches, then set the density to 576/6=96 dpi.

convert .... -units pixelsperinch -density 96 result.jpg

But if the input image is larger, then the whole image will print to larger than 6 inches.

If you want the whole image to print to six inches, then you need to use the image width/6 to compute the density value in dpi

see
http://www.imagemagick.org/script/comma ... hp#density
http://www.imagemagick.org/script/comma ... .php#units

Re: Drawing a Six Inch Box

Posted: 2013-06-25T06:29:39-07:00
by nas
Ok, let me try to clarify what I want. I am scanning objects of various sizes on a flatbed scanner. What I want to do is read the vertical and horizontal resolution metadata to draw a box next to the object I scanned. I want that box to be six inches long when the image is scaled correctly so that I know how big the object is, relative to that box.

Is it possible to do this with the metadata I have, that the vertical and horizontal resolution is 96 dpi?

Thanks,
NAS

Re: Drawing a Six Inch Box

Posted: 2013-06-25T07:00:50-07:00
by holden
What are the actual pixel dimensions of your scanned images, and what size do you want to print them at?

Re: Drawing a Six Inch Box

Posted: 2013-06-25T07:01:55-07:00
by snibgo
nas wrote:Here is the command I'm currently using, but it doesn't seem to work properly:
What is wrong with it? Is the density you are using (96 dpi) correct?

Most scanners seem to work in a multiple of 150 dpi, but software often puts the wrong value in the file.

Posting a sample would be helpful.

Re: Drawing a Six Inch Box

Posted: 2013-06-25T07:15:38-07:00
by nas
I would like to print them at the original size. Thanks @snibgo for the information that most scanners are in multiples of 150. I have found that to be approximately correct, so it may be that I am mistaken in expecting the metadata to be correct. I've uploaded a sample at this URL: http://imgur.com/a/7rLn3
Here is the actual image: Image
And here is the metadata: Image

Thanks,
NAS

Re: Drawing a Six Inch Box

Posted: 2013-06-25T07:31:21-07:00
by snibgo
The image is 825x1604 pixels. If 96 dpi is correct, the scan is 8.6 x 16.7 inches. Does this sound correct?

However ...

Code: Select all

D:\web\im>%IM%identify -verbose xx\9HDSES4.jpg
Image: xx\9HDSES4.jpg
  Format: JPEG (Joint Photographic Experts Group JFIF format)
  Class: DirectClass
  Geometry: 825x1604+0+0
  Units: Undefined
  Type: Grayscale
  Endianess: Undefined
  Colorspace: Gray
  Depth: 8-bit
... IM doesn't give a resolution. I suppose the file doesn't have a resolution, and Windows Photo Viewer invents "96 dpi".

If you have the scanner, I suggest you scan a flat ruler and calculate the dpi. Also take a note of any settings on the scanner software.

Re: Drawing a Six Inch Box

Posted: 2013-06-25T07:34:56-07:00
by nas
Alright, I'll do that. Thank you very much! I'll get back to you if I need anymore. It's a little obnoxious that Windows is pulling these values out of nowhere, but oh well.

Re: Drawing a Six Inch Box

Posted: 2013-06-25T07:57:46-07:00
by snibgo
I recently scanned some documents at 600 dpi (the scanner's natural resolution) and 300 dpi. According to "identify -verbose" and exiftool, the results are all 120 dpi. I suppose the scanner software created the wrong metadata.

If I was fussy, I would use exiftool to adjust the metadata.

Re: Drawing a Six Inch Box

Posted: 2013-06-25T10:54:27-07:00
by fmw42
IM probably does not give a density since the units are undefined. IM may have changed from showing density if units were undefined to not showing them. It might be better to show the density with undefined units and let the user decide which units to use rather than not showing density at all, if that is what it is doing. It is possible also that the density is truly missing.

Exiftool shows a density (resolution of 1) and units of 0. Thus meaningless information.

Code: Select all

---- ExifTool ----
    - ExifToolVersion                 : 8.71
---- System ----
    - FileName                        : 9HDSES4.jpg
    - Directory                       : .
    - FileSize                        : 28482
    - FileModifyDate                  : 2013:06:25 10:49:01-07:00
    - FilePermissions                 : 644
---- File ----
    - FileType                        : JPEG
    - MIMEType                        : image/jpeg
    - ImageWidth                      : 825
    - ImageHeight                     : 1604
    - EncodingProcess                 : 0
    - BitsPerSample                   : 8
    - ColorComponents                 : 3
    - YCbCrSubSampling                : 2 2
---- JFIF ----
    0 JFIFVersion                     : 1 1
    2 ResolutionUnit                  : 0
    3 XResolution                     : 1
    5 YResolution                     : 1
---- Composite ----
    - ImageSize                       : 825x1604
You need to have your scanner add the proper density information.

Re: Drawing a Six Inch Box

Posted: 2013-06-26T06:27:53-07:00
by nas
Ok, thanks all! I've dug into the scanner settings, and it looks like it's going to be 150dpi for all of them. Thank you very much! The fact that Windows was making up values was probably the most confusing part of all of this.

NAS