Resolution Problem

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
pdoak
Posts: 8
Joined: 2019-03-14T07:02:23-07:00
Authentication code: 1152

Resolution Problem

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resolution Problem

Post by fmw42 »

It looks fine at normal resolution. When you enlarge in a viewer, it will pixel replicate. That will make it look bad.
pdoak
Posts: 8
Joined: 2019-03-14T07:02:23-07:00
Authentication code: 1152

Re: Resolution Problem

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resolution Problem

Post 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.
pdoak
Posts: 8
Joined: 2019-03-14T07:02:23-07:00
Authentication code: 1152

Re: Resolution Problem

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Resolution Problem

Post 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.
snibgo's IM pages: im.snibgo.com
pdoak
Posts: 8
Joined: 2019-03-14T07:02:23-07:00
Authentication code: 1152

Re: Resolution Problem

Post 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?
pdoak
Posts: 8
Joined: 2019-03-14T07:02:23-07:00
Authentication code: 1152

Re: Resolution Problem

Post by pdoak »

I think I solved it. The shading is due to the fractional numbers that the command is trying to plot.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Resolution Problem

Post 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'" ...
snibgo's IM pages: im.snibgo.com
pdoak
Posts: 8
Joined: 2019-03-14T07:02:23-07:00
Authentication code: 1152

Re: Resolution Problem

Post by pdoak »

Thanks @snibgo. I realised just as you were posting your answer.
Post Reply