from big png-file image less in width/height with maximum quality

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
mstdmstd
Posts: 2
Joined: 2016-03-31T23:50:06-07:00
Authentication code: 1151

from big png-file image less in width/height with maximum quality

Post by mstdmstd »

Hi all,
I need to make from big png-file image less in width/height with maximum quality, despite of its size
I use imagemagick command like:

Code: Select all

/usr/bin/convert -sample 1201x847 -density 600   "source_file.png"  -quality 100   "dest_file.png"

I get png file but I would like to get image of better quality...

I set width/height of output file as -sample 1201x847
That is clear with -quality 100 - best quality

Not clear with density parameter
I read a doc:
-density width
-density widthxheight
Set the horizontal and vertical resolution of an image for rendering to devices.
This option specifies the image resolution to store while encoding a raster image or the canvas resolution while rendering (reading) vector formats such as Postscript, PDF, WMF, and SVG into a raster image. Image resolution provides the unit of measure to apply when rendering to an output device or raster image. The default unit of measure is in dots per inch (DPI). The -units option may be used to select dots per centimeter instead.
The default resolution is 72 dots per inch, which is equivalent to one point per pixel (Macintosh and Postscript standard). Computer screens are normally 72 or 96 dots per inch, while printers typically support 150, 300, 600, or 1200 dots per inch. To determine the resolution of your display, use a ruler to measure the width of your screen in inches, and divide by the number of horizontal pixels (1024 on a 1024x768 display).
If the file format supports it, this option may be used to update the stored image resolution. Note that Photoshop stores and obtains image resolution from a proprietary embedded profile. If this profile is not stripped from the image, then Photoshop will continue to treat the image using its former resolution, ignoring the image resolution specified in the standard file header.
The -density option sets an attribute and does not alter the underlying raster image. It may be used to adjust the rendered size for desktop publishing purposes by adjusting the scale applied to the pixels. To resize the image so that it is the same size at a different resolution, use the -resample option.
Did ther mean params of monitor of client screen.width and screen.height ?
As it was written:
use a ruler to measure the width of your screen in inches, and divide by the number of horizontal pixels (1024 on a 1024x768 display
It was not actually very clear about these parameters and how to calc it.

Also googling I see using of parameters -sharpen, -trim, -resample - do they influence quality of resulting and if yes how to use them ?

About source png file I know only that it is result of fabrics js canvas using html2canvas function.

How to get image of better quality?

Thanks!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: from big png-file image less in width/height with maximum quality

Post by snibgo »

mstdmstd wrote:/usr/bin/convert -sample 1201x847 -density 600 "source_file.png" -quality 100 "dest_file.png"
1. Don't use "-sample". For better quality, use "-resize".

2. "-quality 100" doesn't affect the quality of PNG output. For PNG, the quality is always perfect. It affects only the amount of compression.

3. "-density" is for pixels per inch or pixels per centimetre, not the total number of pixels. It is only metadata, and does not affect the image.

4. Put the command in the correct order: read the input, process it, write the output.

So, try:

Code: Select all

/usr/bin/convert "source_file.png" -resize 1201x847 "dest_file.png"
snibgo's IM pages: im.snibgo.com
Post Reply