Page 1 of 1

Resolution Problem

Posted: 2019-04-23T10:54:25-07:00
by pdoak
I am using ImageMagick to draw a rounded rectangle with this command:

Code: Select all

 convert -size 665x848 xc:transparent -fill None -stroke white -strokewidth 0.5 -density 1200 -units PixelsPerInch\                                                                                   [18:41:59]
          -draw "roundrectangle 31.63,705.24,219.47,711.5 2,2"  draw_rrect.png
However, the resolution does not look that good as can be seen below:

Image
https://imgur.com/pQJ6bAg

Is there a way to increase the quality of the image?

Re: Resolution Problem

Posted: 2019-04-23T11:20:06-07:00
by fmw42
It looks fine at normal resolution. When you enlarge in a viewer, it will pixel replicate. That will make it look bad.

Re: Resolution Problem

Posted: 2019-04-23T13:33:04-07:00
by pdoak
Thanks fmw42 for your reply.

I need the image for an A1 size physical print so I need the resolution to be better than the command that I showed in the original post. Is there a way to improve the quality?

Re: Resolution Problem

Posted: 2019-04-23T15:28:06-07:00
by fmw42
Draw a larger round rectangle and resize it down. If you make it a lot larger, be sure to increase the stroke width. Alternately, create it as SVG using SVG tools that keep it as a vector.

Re: Resolution Problem

Posted: 2019-04-25T04:45:22-07:00
by pdoak
Thank you for your suggestion. As I need the shape to be in the exact location and of the correct size, I am not sure that enlargening and then resizing will solve my problem.

I feel as though I am missing something as if I use this command to generate a line:

Code: Select all

      convert -size 665x848 xc:transparent -fill '#12C3FB' -stroke '#12C3FB' -strokewidth 5.26 -set colorspace RGB\
        -draw "stroke-linecap round        path 'M 32.13 711 L 186.86 711'" \
        -colorspace sRGB line.png
It generates the following image when blown up:
Image

If I create the same line in Figma and export it at 4X and blow up it generates a much better image:
Image

I want to be able to produce the same quality with ImageMagick if possible.

Re: Resolution Problem

Posted: 2019-04-25T07:39:12-07:00
by snibgo
If you want an A1 size print, this is 841mm x 594mm. At (say) 10 pixels/mm, you want an image 8410x5940 pixels. This is much larger than your "-size 665x848".
pdoak wrote:As I need the shape to be in the exact location and of the correct size, I am not sure that enlargening and then resizing will solve my problem.
Possibly not, but I'm not sure what problem you want to solve.

If your rounded rectangle is only about 6 pixels high, from y=705.24 to 711.5, then that's the height it will be. You can make a bigger rectangle then resize it down, but that will also be only about 6 pixels high.

Why are you scaling it up? If that's the result you want, you should make it that size.

Re: Resolution Problem

Posted: 2019-04-25T08:26:27-07:00
by pdoak
Thank you @snlbgo.

I have scaled everything up, and now the resolution is in line with the output from Figma. This code:

Code: Select all

convert -size 2660x3392 xc:transparent -fill '#12C3FB' -stroke '#12C3FB' -strokewidth 21.04 \
        -draw "stroke-linecap round        path 'M 128.52 2844 L 747.44 2844'" \
          line.png
generates this image.

Image

Why is the straight line at the top and bottom of the stroke in a shade of blue and not in the light blue? Is there a way to resolve this?

Re: Resolution Problem

Posted: 2019-04-25T08:48:12-07:00
by pdoak
I think I solved it. The shading is due to the fractional numbers that the command is trying to plot.

Re: Resolution Problem

Posted: 2019-04-25T08:50:37-07:00
by snibgo
Yes, that's it.
pdoak wrote:Why is the straight line at the top and bottom of the stroke in a shade of blue and not in the light blue? Is there a way to resolve this?
The reason is that the top and bottom of the lines do not occur at pixel boundaries. For example, your strokewidth is 21.04, so either the top or bottom or both will be antialiased.

You can "+antialias" before "-draw" to turn off antialiasing, but then the rounded ends will be stepped.

Or you can set the width and start-y and end-y to integers plus 0.5. For example:

Code: Select all

... -strokewidth 21.5 \
-draw "stroke-linecap round path 'M 128.52 2844.5 L 747.44 2844.5'" ...

Re: Resolution Problem

Posted: 2019-04-25T08:53:43-07:00
by pdoak
Thanks @snibgo. I realised just as you were posting your answer.