When I convert PNG images from 140x140 to 100x100, the image quality suffers - image-processing

When I convert PNG image from 140x140 to 100x100, the image quality suffers.
I have tried this command
convert "image.png" -thumbnail 100x100 -quality 100 "out.png"

Related

Why Graphicsmagic produces thumbnails much larger in file size that Imagemagick?

input.jpg is 3264×2448 px, 1.78 MB.
I have created two thumbnails with identical arguments, in imagemagick 7.0.8-11:
convert input.jpg -quality 50 -thumbnail 200x200 thumb_im.jpg
and graphicsmagick 1.3.30:
gm convert input.jpg -quality 50 -thumbnail 200x200 thumb_gm.jpg
The results are: imagemagick — 4.31 kB, graphicsmagick — 27.8 kB. Visually these images are similar in quality but not identical.
What am I missing?

How do I convert jpg image to tiff with 300DPI and reduce noise to 100% in Image magic?

I have been working on an image from last 25 days with zero output. So I came here in search of an answer.
I have a jpg image of 7MB. I upload it in Photoshop and changed the width to 96 Inch, Resolution for 300 pixels/inch, checked resample option and selected Preserve Details 2.0 and reduce noise to 100%. It gave me a 1.5 GB image as output.
Now I tried the same steps in image magic
gm convert -scale 768 -units PixelsPerInch -density 300x300 -resample 300x300 -noise 100% image.jpg -resize 768 image.tiff
Above command gave output in KBs. I need help.
If you want a 96inch wide image at 300dpi, you will need a width of 28,800 pixels, so start with:
gm convert input.jpg -resize 28800x result.jpg
That will resize the image to the correct width and do whatever is required with the height to preserve the image's aspect ratio - i.e. without distorting it.

Applying watermark on an image

I'm trying to apply watermark on an image using the following imagemagick command
convert input.png watermark.png.png -gravity northwest -composite output.png
The input png file size is 16KB and the watermark file size is 900bytes, but when I executed the above command to apply a watermark, the output png size is 61KB which is almost 4X the size of the original input png file. Is there any better way of applying a watermark to an image file with much better result in terms of output filesize
Test Image: https://res.cloudinary.com/deks86ilr/image/upload/v1533015495/1_rnpbye.png
Test watermark: https://res.cloudinary.com/deks86ilr/image/upload/v1533015494/2_usmonh.png
Here are my results of processing of your images with my PNG8 output using ImageMagick 6.9.10.8 Q16 with libpng 1.6.34.
I note that your input image was type palette, which means it is 8-bits of color per pixel and not 24-bit color. So it is already a low quality image.
Input (~16 KB):
Watermark Image (white on transparency -- so it is invisible here):
Convert to 24-bit PNG:
convert input.png watermark.png -gravity northwest -compose over -composite input_with_watermark.png
I see no significant visible quality loss but the output is now increase from 16 KB to 60 KB. But you can use tools such as pngcrush to compress it further.
Convert to 8-bit PNG:
convert input.png watermark.png -gravity northwest -compose over -composite PNG8:input_with_watermark2.png
The file size is now back to about 16 KB. But as you note the quality is a little poorer. This is likely because the input image (at 8-bits and has 217 colors) was first read back to 24-bits, then watermarked, which included new shades of white and then quantized back to 8-bits, but contains only 84 colors colors.
Another way is to add +dither -colors 256 to the command (the +dither turns off dithering):
convert 1_rnpbye.png 2_usmonh.png -gravity northwest -compose over -composite +dither -colors 256 PNG8:watermark3.png
This is a bit better, since it now uses 189 colors and still has a file size of 16 KB.
One final method is to save the colors from your input to a colortable image. Then use -remap to recolor the output using that colortable:
convert 1_rnpbye.png -unique-colors colortable.gif
convert 1_rnpbye.png 2_usmonh.png -gravity northwest -compose over -composite +dither -remap colortable.gif PNG8:watermark4.png
This results in 8-bit output with 227 colors and still a file size of about 16 KB. So it has a few more colors than your input and visually looks about the same quality as your input.
If you cannot reproduce these results, then perhaps you should upgrade either or both ImageMagick and libpng.

How to strip png images using ImageMagick?

convert -strip -interlace JPEG -quality 80 origi.jpg output-file.jpg
origi image size : 40.6 kb
output-file image size : 11.3 kb
But if I convert one png file as
convert -strip -interlace PNG -quality 80 he.png output-file.png
he.png image size : 711 kb
output-file image size : 1 mb
convert -strip -interlace PNG he.png output-file.png
he.png image size : 711 kb
output-file image size : 972.3 kb
Why the file size has been increased in case of PNG after conversion to output-file.png?
Am I using correct parameters for png conversions?
If you convert a regular PNG image into an interlaced one, the resulting filesize will probably be larger, as explained in the PNG specification (emphasis added):
Pass extraction ... splits a PNG image into a sequence of
reduced images (the interlaced PNG image) where the first image
defines a coarse view and subsequent images enhance this coarse view
until the last image completes the PNG image. This allows progressive
display of the interlaced PNG image by the decoder and allows images
to "fade in" when they are being displayed on-the-fly. On average,
interlacing slightly expands the datastream size, but it can give the
user a meaningful display much more rapidly.
The "-quality 80" option was not helpful because that forced ImageMagick to not use "filtering" to improve compression.

Why does convert png->jpg blow a picture up to the original size?

I have a png whose width is 2551 pixels and whose height is 3578 pixels.
On this png, I use the -crop option of convert to cut out an image whose dimensions are 2362 x 3389 pixels:
convert original_2551x3578.png -crop 2362x3389+94+94 crop_2362x3389.png
This works as intended.
Then, I use convert to create a jpg:
convert crop_2362x3389.png -format jpg -flatten -background white out.jpg
I expected this command to produce a jpg with the same dimension (2362 x 3389). Much to my surprise, the produced jpg has the dimension 2551 x 3578 pixels (which is the same as the original image).
So it seems that somehow the original size is stored along with crop_2362x3389.png.
How can I use convert to convert a png into a jpg and have it keep the dimension of crop_2362x3389.png?
The reason you are seeing this is that when you do your initial crop, the image "remembers" it was part of a larger image and where in that image it used to be.
You can see this if you do your original crop and then run identify and look at the 4th field, just left of 8-bit.
convert original_2551x3578.png -crop 2362x3389+94+94 crop_2362x3389.png
You can also tell ImageMagick to "forget" it by using +repage like this:
# Repage after changing geometry to forget earlier geometry
convert original_2551x3578.png -crop 2362x3389+94+94 +repage crop_2362x3389.png
# Check IM has forgotten image used to be a part of a bigger one
identify crop_2362x3389.png
crop_2362x3389.png PNG 2362x3389 2362x3389+0+0 8-bit sRGB 256c 15.1KB 0.000u 0:00.000
Ok, I've found a solution. The geometry after the -crop parameter must be followed by a !:
convert original_2551x3578.png -crop 2362x3389+94+94! crop_2362x3389.png
This works as intended.

Resources