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.
Related
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?
For e.g.
magick -density 100 apple.jpg -resize 100x100 apple-edited.jpg
Density here is the option which has to be provided prior to input file name.
Can someone please explain when is such prior options are needed. And also provide me few more examples.
PS: I tried looking for the options but not sure if there is an specific term for such options which will help limit the search results.
ImageMagick is, exclusively, a raster image processor, which means that it processes bitmap images made up of pixels laid out on a rectangular grid (or raster), rather than a vector image processor like Adobe Illustrator or Inkscape which deal with shapes, lines, rectangles and bezier curves described by their vertices or inflection points - not pixels.
When you load a vector image (e.g. an SVG image, or a PDF) into ImageMagick, the very first thing it does is rasterise your image onto a rectangular grid before it can work with the pixels. So, if your image is an SVG or a PDF, you need to set the density, or number of lines in the grid before you load the image.
I don't know of a reason to do that for a JPEG, like your example. I can't think of any other settings you absolutely need to make prior to loading an image.
I am working on a project to recognize text in Business Cards and map them to appropriate fields.I am using opencv for image processing.I need to feed the preprocessed image to Tesseract-OCR engine for text recognition.This link
states that images should have atleast a DPI of 300.My image pixel size is 2560x1536 with 72 DPI.
How to increase the DPI to 300?
It is also said that it is beneficial to resize image.How to resize my image optimally for good OCR results
Tesseract works best on images which have a DPI of at least 300 dpi, so it may be beneficial to resize images. What does 'so' imply here.What is the relation between resizing an image and DPI?
For OCR, what really matters is the resolution in pixels. Because the physical characters can range from tiny to huge, independently of the DPI of the acquisition device.
As a rule of thumb, stroke width around 3 pixels is a good start. If lower, resizing might not be helpful because the information is missing. If much higher, the running time might be excessive (or the OCR function not be taylored to deal with it).
Also check that the package will not attempt to resize internally, based on its own assumption of stroke width and the DPI info stored in the header, if there is a mismatch.
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.
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)