Page 1 of 1

Command line: set density to get cm without resizing

Posted: 2018-09-24T09:28:45-07:00
by stringeater
<t>Hello<br/>
<br/>
I have joined the ImageMagick discourse today – hello everybody.<br/>
<br/>
I make screenshots of line graphics, trim them with ImageMagick and paste them into a Word document.<br/>
I would like to set the density to get the desired width in centimeters without changing the size in pixels. This means that I will set meta data without touching the pixels.<br/>
Is there a single-line command line that reads the width and calculates the density? Something like this to get a width of 7.7cm:<br/>
<br/>
magick convert clipboard: -units PixelsPerCentimeter -density '(%w/7.7)' clipboard:<br/>
<br/>
How do I have to write it correctly?<br/>
<br/>
I have found other posts, but I have not found any single-line examples.<br/><br/>
Thanks in advance.<br/>
stringeater<br/><br/>
Version: 7.0.8-11 Q16 x86 2018-09-29 / Windows 10</t>

Re: Command line: set density to get cm without resizing

Posted: 2018-09-24T09:48:55-07:00
by fmw42
I do not know much about clipboard: but I think the correct syntax for the density would be '%[fx:w/7.7]'

Computations cannot be done with string formats such as %w. But they can be done in fx expressions as above.

If you want to add style use the buttons above the editing window rather than adding HTML code.

Re: Command line: set density to get cm without resizing

Posted: 2018-09-24T11:27:25-07:00
by stringeater
Hi fmw42

Thanks for your extremely quick reply.
Unfortunately I get the error message:
convert: Invalid Argument '-density': '%[fx:w/7.7]' @ error/convert.c/ConvertImageCommand/1309.

My complete command line was:
magick convert clipboard: -units PixelsPerCentimeter -density '%[fx:w/7.7]' clipboard:

Using clipboard: seems not to be a problem. The following command line works well:
magick convert clipboard: -units PixelsPerCentimeter -density 100 clipboard:

What was wrong with my command line?

Regards, stringeater

Re: Command line: set density to get cm without resizing

Posted: 2018-09-24T11:32:46-07:00
by snibgo
Use just "magick", not "magick convert".

Using "magick convert" gives you v6 syntax, which doesn't allow expressions in "-density". V7 syntax does.

Re: Command line: set density to get cm without resizing

Posted: 2018-09-24T11:50:32-07:00
by stringeater
snibgo, thanks for this remark. I would have tried endlessly.
I had to remove the apostrophs to avoid another error message. This command line finally worked:

magick clipboard: -units PixelsPerCentimeter -density %[fx:w/7.7] clipboard:

Thank you fmw42 and snibgo! You have been very helpful

Regards, stringeater

Re: Command line: set density to get cm without resizing

Posted: 2018-09-24T14:27:41-07:00
by fmw42
Windows can work without quotes, but in Unix, the quotes are needed. I think double quotes will work in Windows, but I will defer to Windows experts on that issue.

For other differences, see https://imagemagick.org/Usage/windows/

Re: Command line: set density to get cm without resizing

Posted: 2018-09-25T09:43:20-07:00
by stringeater
Yes, double qoutes work, but not single apostrophs.
Thanks for the link to a lot of information.