What flag in magick.exe convert <flags> will reduce the dimensions of my image?
This is the command I'm using: magick.exe input.png[0] -depth 8 -type Grayscale -dresize 400x300.
The [0] after the source-image filename is meant to strip the first frame of any animated gifs.
How can I do reduce my output gif sizes? My file sizes are too large: my outputs need to be less than 100k. Any methods other than reducing the dimensions are also welcome.
convert test.gif -fuzz 10% -layers Optimize result.gif
Adding a -fuzz 2% produced a better optimization, but still not very good. At -fuzz 15% It isolated the differences for frame optimization to just the visible color band changes I noted before.
At 25% the differences were almost to just the text changes.
Finally at a massive 30% fuzz factor (ignore color changes below that figure, did it optimize to just the text changes.
You can try gifsicle:
gifsicle -O3 old.gif -o new.gif
If it's an animation, you could try skipping frames (see how it works).
magick.exe convert -resize 100x100 .\step1.jpg .\step2.jpg -delay 100 -loop 0 animation.gif
Thanks to Nate.
//IMPORTANT: -resize should come first.
//BY DEFAULT: the aspect ratio will be locked with the longest dimension being set to 100px.
//GENERALIZATION: this order `magick convert 1st<input_file(s)> 2nd<switch(es)> 3rd<output_file>`.
//IMPORTANT-RELATED: `-delay` will not work on second brush! Use `-set delay` for existing files.
Please, also be sure to refresh your folder view to ensure that you're not viewing old output files: Windows Explorer (F5).
Try to use the option:
-type Palette
It might help to reduce your gif file sizes smaller, oh and I believe -depth 8 can only be used for png images.
Related
im trying to resize image from 72x72 to 512x512 with following command
convert input.png -resize 512x512 output.png
but the output image (output.png) become blur
how to prevent resized images from becoming blurred
how to prevent resized images from becoming blurred
If you want a pixelated image of the original use -sample
# Create small image.
convert -size 72x72 plasma: 72x72.png
# Magnify the image with pixel subsampling.
convert 72x72.png -sample 512 512x512_sample.png
It's true that you can't restore missing data when upscaling images, but there's a lot of various algorithms to calculate what may be missing.
Try using the -filter option in addition to -resize, and checkout the wonderful usage examples here.
Probably the best you can do is use a sharper -filter such as catrom and then do post processing using -unsharp.
convert input.png -filter catrom -resize 512x512 -unsharp 0xSigma output.png
where sigma is the sharpening value, try sigma=1 or 2 (or as desired)
But it will not maintain the same quality as the input as others have mentioned above.
See -unsharp at http://www.imagemagick.org/script/command-line-options.php#unsharp
You can't. For an equal sharpness, you would need more data in the bigger image. Since you have only the data from a small image the result is blurred.
Look at it the other way, if what you asked was possible, instead of compressing the 512x512 image, we would first scale it down to 72x72, compress that (much smaller file) and sent it over with instructions to scale it up to 512x512.
I've read the ImageMagick documentation here and here and been unable to achieve a couple of simple tasks. Would appreciate any simple pointers or direction, or even commands I can execute that will work on Linux.
I want to convert any image-type (JPG, GIF, PNG, TIFF) to save to a PNG, losslessly, and as compressed as possible without any loss of quality. Ideally in 96 DPI so they look good in Retina screens.
To then take the above generated PNG and also resize it in specific sizes, with height and width specified.
What am I missing with the convert command?
If you want to convert a TIF, GIF or JPEG to PNG, the command is:
convert image.tif result.png
or
convert image.jpg result.png
In answer to your questions...
Question 1
PNG is lossless by definition, so that is not an issue. To get better compression of a PNG, you generally need to reduce the colours, i.e.
convert image.jpg -colors 64 result.png # or try 255 which allows a palettised image
The dpi is pretty irrelevant until you print on paper. More pixels are needed if you want more quality on screen.
Question 2
If you want to resize an image without destroying its aspect ratio, use
convert image.jpg -resize 200x100 result.png # retain aspect ratio
If you don't care if that makes the image look stretched or distorted, and you want exactly 200x100, tell ImageMagick that you really mean it by shouting:
convert image.jpg -resize 200x100! result.png # ignore aspect ratio
There's plenty of information about cropping images, but attempting to crop (or trim) animations produces strange results. Sometimes they flicker, or come with extra frames, or some frames crop correctly and others become offset. How do I prevent all this from happening?
convert input.gif -coalesce -repage 0x0 -crop WxH+X+Y +repage output.gif
Animated gifs are often optimised to save space, but imagemagick doesn't seem to consider this when applying the crop command and treats each frame individually. -coalesce rebuilds the full frames.
Other commands will take into consideration the offset information supplied in the original gif, so you need to force that to be reset with -repage 0x0.
The crop itself is straightforward, with width, height, x offset and y offset supplied respectively. For example, a crop 40 wide and 30 high at an x offset of 50 = 40x30+50+0.
Crop does not remove the canvas that it snipped from the image. Applying +repage after the crop will do this.
Even with the coalesce and repage, I could not get ImageMagick to crop and resize animated gifs very well.
I found a program called Gifsicle and it works great for manipulating animated gifs.
gifsicle --crop 0,0-100,100 --output out.gif in.gif
It can also do all sorts of other operations. Check it out!
Animations are often optimized, which means that some frames are smaller than others. So in ImageMagick you probably want to coalesce the animation before cropping.
convert in_animation.gif -coalesce -crop WxH+X+Y +repage -layers optimize out_animation.gif
You may need to add a -dispose method before reading the input animation to avoid a flicker. Also set the -delay and -loop at the end, if you want to make changes.
See
http://www.imagemagick.org/Usage/anim_basics/#dispose
http://www.imagemagick.org/Usage/anim_basics/#coalesce
http://www.imagemagick.org/script/command-line-options.php#layers
The following line worked with me on Mac
convert -dispose 2 input.gif -trim -layers TrimBounds animation.gif
Here is the source
I am converting various PDFs uploaded by end users into images using following command
-density 140 -limit memory 64MB -limit map 128MB [pdffile] page.png
Here is the result. On the right we have original PDF and on the left output image. As you can see the colors are quite noticeably different.
What could be causing this and how fix it?
try following command:
-density 140 -limit memory 64MB -limit map 128MB -colorspace RGB [pdffile] page.png
Edit: I later discovered that ImageMagick can do it fine, I just needed to use -colorspace sRGB
My final command was:
convert -density 560 -limit memory 64MB -limit map 128MB \
-colorspace sRGB [pdffile] -scale 25% page.png
The oversampling and scaling down was to counter the poor anti-aliasing mentioned below.
Before I discovered that, here was my earlier solution...
In my case the colors produced by ImageMagick's convert were oversaturated, quite like those in the question. I was trying to convert this file using IM 6.7.7.10-6ubuntu3.
-resample 100 made no difference.
-colorspace RGB seemed to produce more accurate saturations, but the entire image was darker than it should have been.
Curiously, this suggestion to use GhostScript instead of ImageMagick for the conversion, produced very close to the correct colors:
gs -q -sDEVICE=png16m -dSubsetFonts=true -dEmbedAllFonts=true \
-sOutputFile=page.png -r200 -dBATCH -dNOPAUSE [pdffile]
(The original suggestion passed the -dUseCIEColor option, but in my case this appeared to reduce the gamma: light pixels were fine, but the dark pixels were too dark, so I removed it.)
After that, the only thing that bothered me was that the anti-aliasing/edges were a little off in places (especially visible on curves passing 45 degrees). To improve that, I created the output at four times the required resolution, and then scaled down afterwards, rendering those errors almost imperceptible. Note that I had to use ImageMagick's -scale for this, and not -geometry or -resize, in order to avoid bicubic ringing effects.
Use the -resample option:
-density 140 -resample 100 -limit memory 64MB -limit map 128MB [pdffile] page.png
Open Source MuPDF util mutool retains color and size using default parameters below
you need though to list the pages separated by a comma at the end of the command.
mutool draw -o draw%d.png abook.pdf 1,2
Otherwise if using Linux try Windows for better colorspace RGB interpretation when using imagemagick's convert.
The following images show how anti-aliasing improves if you sample at a higher resolution and then scale down.
Although 1120 was slightly better quality than 560, it took a long time to convert, so I would probably choose 560 for a good time:quality trade-off.
-colorspace sRGB -density 140
-colorspace sRGB -density 280 -scale 50%
-colorspace sRGB -density 420 -scale 33.3333%
-colorspace sRGB -density 560 -scale 25%
-colorspace sRGB -density 1120 -scale 12.5%
(It is easier to see the difference if you download the last two images and flip between them in your favourite image viewer. Or scroll up this list of images, instead of down. You should seem them becoming progressively uglier.)
I converted a 2.9M jpg to a 20x20 using 8 as the quality. but that file's size is still 48k.
here is my command
convert 238832c58dc3bc0b_29M.jpg -quality 8 -resize '20x20>' +repage 238832c58dc3bc0b_20x20.jpg
and after conveted, 238832c58dc3bc0b_20x20.jpg is 48k. I tried smalled size and quality, still 48k. it shouldn't be so big. it should be less than 10k. anybody know how to enhance it? thanks
Use -thumbnail instead of -resize or add -strip to your command.
Thumbnail removes the EXIF information apart from the color profile and strip removes the color profile as well.