Does ImageMagick decrease image quality by default? - imagemagick

I use ImageMagick to convert images from one format to another, to convert them into a single PDF, to rotate them according to camera orientation, to trim white space, or sometimes to change resolution.
When doing these tasks, I never want to decrease image quality. I would always prefer to preserve the quality as high as possible.
The description of the -quality parameter confuses me. If I understood its description correctly, ImageMagick always slightly decreases the image quality during conversions.
Is it really so? Does it mean I should use -quality 100 as a safety belt each time I use ImageMagick?

Related

PNG Compression Not Reducing the size of images

I have certain png files. They are of size approx 1MB. I tried several command but they didn't work for me. Any suggestions. One is as below :
"C:\\Program Files\\ImageMagick-6.9.9-Q16\\mogrify.exe" -depth 8 -format png -define PNG:compression-strategy=2 -define PNG:compression-filter=0 test.png
Thanks,
As pointed out by #fmw42 in comments, your image may already be optimized. Also, #Mark's comment regarding reducing colors is true.
But apart from this, the important thing to know is that "there is no ideal command". You will have to figure out bit depth in your color channels and reduce them. There will always be a trade-off between reducing colors and quality you wish to pick.
Apart from that, there can also be other methods that you can use:
If opacity of PNG is fully opaque, you can strip alpha channel as it
makes no sense in that case. This can give you some file size savings.
If the image is visibly grayscale and still color type is
true-color, true-color-alpha or indexed-color, you can make significant savings by saving the image with a grayscale color space.
Retry optimizing PNG files using adaptive delta filtering and LZ77 Optimizations. This can be done easily using "optipng". But if the image is already optimized enough, this won't provide significant file sizes reduction. Moreover, choice of filtering depends upon png bit depths, so you would have to look up and understand PNG compression from various documentation available online regarding PNG compression.

Why am I losing image quality with imagemagick when reducing a very large image to a much smaller image?

I have a bunch of images that I want to convert into a single PDF, the images are primarily images of text (similar to scanned images of a textbook). The image files are extremely large, I have no need for the amount of resolution that they offer.
So first, as a base file, I did a simple conversion of 26 of these "pages" to a single pdf, and the total filesize was 46MB for 26 pages. Viewing in page width mode resulted in a scale of 16% of the original image.
convert *.png kapittel1.pdf
The quality of the PDF pages was perfect, they were just too large. So I figure since 16% of the image is more than adequate for viewing the entire width of the page on my screen, I could reduce the image sizes to 20% of their original values and still maintain the same image quality. The quality of the images is visibly less than before reducing the size.
convert -resize 20% -quality 100% *.png 20percent.pdf
I believe I'm going to need to start looking into filters, but before I potentially waste my time converting using all of the filters then comparing to find the one I want to use, is there a better way to just reduce the size, maintain quality, then convert to PDF? I don't see why I would be losing pixels here.
Edit
I tried with -scale instead of -resize but am really not seeing a difference in the output. It pretty much seems that once I go below 40% I start losing pixel data.
The excellent ImageMagick Examples state that by default, no image compression is used when creating PDFs and suggest to use Zip (Deflate Compression):
convert *.png -compress Zip -quality 100 kapittel1.pdf
If your images are only black and white, you can try the -monochrome option and optionally Group4 (Fax) compression using -compress Group4.
Ok well I discovered that the size of the PDF once following Shawn Patrick Rice's suggestion for Optimizing Scanned PDFs and OCR+ClearText was fairly negligible between a -resize setting of 30-50%. The primary goal here is to reduce the size of the resulting PDF to under 45" in height as this is the threshold for Adobe's OCR. I found no benefit from converting each image individually to a PDF then resizing, or playing with the plethora of other settings in Adobe. The below process kept (as far as I can tell) all of the image quality and reduces the images to the smallest size PDF (at full quality).
My process was as follows:
convert *.png -resize 50% name.pdf
// resize amount dependent on original file dimensions, goal is document height < 45"
Adobe Acrobat => Document Processing => Optimize Scanned PDF (Edit => ClearScan output style) => OK
The size of the resulting PDF document is still quite large, however the size after reducing in Adobe goes down considerably (90MB => 4MB). If I first resized at 30% there would be noticeable image quality loss, however the amount of size I would save after optimizing would be around 800KB for the above file.

Should I save an existing jpeg as a jpeg or as a png if I'm slightly altering it with a graphical overlay?

In particular, I'm using ImageMagick to draw a square over the jpeg, with a transparent fill and a pretty thin stroke?
My intuition says that the straight lines of the stroke might appear blurry, but that's less important than maintaining the quality and size of the original image.
Is there anything else that I should take into consideration?
Jpeg is lossy: compresses more but the quality decreases. You should try different levels of compression and comprare the results ( quality and size) against the png version. It may depend a lot on the contents of the image ( some images compress better than others)

resize image without losing quality with Gimp

i have a bunch of images which are way too big i need to decrease their size from 30 kb to 10 or 5 kb without loosing quality. I tried to change the dpi and pixels with no succeed. The images got blurred, and as they have text i can't read anything after the changes. Is there anyway i can accomplish this without loosing quality? I have almost a dozen images in my application.
Thanks in advance and have a nice day.
for batch resizing I use IrfanView (despite it's "lite-ness" it's very powerful).
It has a nice batch dialog, with a lot of options.
If you're working with png files try using better compression, and/or different color depth settings (if you're not using transparency you could try converting them to jpeg, although you might lose some quality)
changing color depth/range/compression might not affect image quality (not visibile anyway, if used with moderation) and it will decrease the size of the picture - in most of the cases anyway
if you want to stick to Gimp (I never personally used it), it should have some export features where you can select some settings for the image, like format and options
You cannot leave out data without reducing quality. Data has meaning.
You may try to use improved compression, pngcrush is the tool that automatically tries several approaches for you and picks the best.
Reducing colour depth will reduce the file size (while reducing colour quality). You can also turn on dithering in some image editors, but that's another loss in quality.
If your image has photographic content rather than graphical, convert to JPEG and use the JPEG quality settings, experiment with them a bit.
It seems that if I have a large png of 2500px wide and I want to resize it down to 100px wide, If I scale the image all at once the the desired size the image becomes way to distorted to use.
However If I scale the image in small increments of 200 pixels and repeat until you reach the desired length the image does not get as distorted. So if Im at 2500px then I would scale the image to 2300px then to 2100 and so on. The smaller the scale the less distortion.
Any resize method will have some loss, no matter how small. Following steps will make you lose quality.
steps for a single layer
layer->scale layer
image->scale image
image->fit canvas to layer
file->export as
steps for multiple layers
layer->new layer group
move all layers to layer group
select layer group
layer->scale layer
image->scale image
image->fit canvas to layer
file->export as

ImageMagick help -- need to change DPI

I have a 1000x1000 300dpi image that I need to convert to a 100x100 96dpi thumbnail. How do I do this in ImageMagick? I'm after the smallest possible file size at the highest possible quality.
Doing something like this:
convert myimage.png -quality 100 -resize 100 PNG8:mynewimage.png
.... does change the dimension, but still maintains the DPI. If I can get this to change to 96dpi, I should get a smaller file size.
I've tried -density, etc., but can't seem to make them work for me. Maybe I put the commands in the wrong order or passed the wrong parameters. Any assistance is greatly appreciated. Thanks.
The short version is, if you want a 100x100 image in PNG format, the line you have will already give you best quality at smallest file size. You can't do any better than that without a) coding to a lossy format (JPEG) or b) reducing the color depth of your image.
For a slightly longer explanation, straight from Wikipedia: "Dots per inch (DPI) is a measure of spatial printing or video dot density, in particular the number of individual dots that can be placed in a line within the span of 1 inch (2.54 cm). The DPI value tends to correlate with image resolution, but is related only indirectly."
DPI has nothing to do with getting a smaller file size; your 100x100 image measures 100x100 pixels, no matter whether you see it on a 300dpi screen or a 96dpi one (it will just look smaller on the 300dpi screen). The amount of information is the same either way.
"-density" won't help either, as it only works when "encoding a raster image while rendering (reading) vector formats such as Postscript, PDF, WMF, and SVG into a raster image". Those formats are resolution-independant, so it makes sense to tell ImageMagick the DPI to which you want the image rasterized. However, your DPI should be a function of the output device you plan to use. In your case, since you're starting with an already-rasterized image, this has no use.
PNG is a lossless format, so the -quality parameter only controls the zlib compression level; any gains in image size will be minimal, but it's worth using.

Resources