I am trying to apply a resize limit for ImageMagick but it does't seem to work as supposed in the docs. I am using ImageMagick 6.9.2-3-portable-Q16-x86 in Windows 7.
convert input.jpg -resize 1920x1080^> -quality 92 output.jpg
When the input file is larger that 1920x1080, it gets resized nicely.
When the input file is smaller, e.g. 1024x768, although I would expect it to be untouched, it does get saved with the same resolution (1024x768) and different file size, depending on the quality set.
Shouldn't parameter -resize 1920x1080^> force ImageMagick to skip that file?
If not, then how can we skip those files that are smaller than the resize limit set?
It is supposed to work like that... your command says "Take input.jpg and resize it if larger than 1920x1080, then change its quality and save it."
You can run something like this before you execute your command to see if it needs resizing - it will output 1 or 0 depending on whether the image needs resizing or not:
identify -format "%[fx:(w>1920)||(h>1080)?1:0]" 1921x1080.jpg
1
identify -format "%[fx:(w>1920)||(h>1080)?1:0]" 1920x1080.jpg
0
If you want to put that 0 or 1 in a variable, you do something like:
for /f "usebackq" %i in ( `identify -format "%[fx:(w>1920)||(h>1080)?1:0]" 1921x1080.jpg` ) do set resize=%i
and double up the percent signs in a .BAT file.
Related
The following command resizes the larger dimension to 256:
convert -resize 256x256 in.jpg out.jpg
For example, if in.jpg is 1024x512, it resizes it to 256x128.
Is it possible to resize the smaller dimension to 256 (while keeping the aspect ratio) with ImageMagick convert? (I need 512x256)
If not, is there any other easy command line solution?
The fill area flag ^ seems to do exactly what you want:
convert -resize 256x256^ in.jpg out.jpg
If you're on Windows:
The Fill Area Flag ('^' flag) is a special character in Window batch scripts and you will need to escape that character by doubling it. For example '^^', or it will not work.
This only works with ImageMagick 6.3.8-3 and above. For older versions, use this trick.
Maybe the command I suggested in my comment will work, namely
convert in.jpg -resize x256 out.jpg
Or, if you actually want to identify the smaller dimension and resize that explicitly, this should do the trick
#!/bin/bash
image=$1
cmd="x256"
[ $(identify -format "%[fx:w<h?1:0]" "$image") -eq 1 ] && cmd="256x"
convert "$image" -resize $cmd out.jpg
I preset the command to resize by height at line 3. Then I ask ImageMagick to output 1 if the image is taller than wide, and if it is, I change the resize command to resize by width. Then, finally, I do the actual resize. You can re-cast the script various ways to make it shorter, or leave it explicit.
E.g.
if [ $(identify -format "%[fx:w<h?1:0]" in.jpg) -eq 1 ]; then
convert in.jpg -resize x256 out.jpg;
else
convert in.jpg -resize 256x out.jpg;
fi
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.
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.
I have a .eps file that I can look at in Photoshop, and it has a very high resolution, sharp edges, etc. at even larger than 1024x1024.
With ImageMagick I want to convert this .eps to a 1024x1024 .jpg with very high resolution.
However, with the following command, the image is very blurry:
convert -resize "1024x1024" -colorspace RGB -flatten test.eps test.jpg
What ImageMagick parameters do I have to use so that the resulting .jpg is 1024x1024 and a high quality, sharp image?
here's some XMP data we found, perhaps what is causing it to not be resized with -size:
For vector graphics, ImageMagick has both a render resolution and an output size that are independent of each other.
Try something like
convert -density 300 image.eps -resize 1024x1024 image.jpg
Which will render your eps at 300dpi. If 300 * width > 1024, then it will be sharp. If you render it too high though, you waste a lot of memory drawing a really high-res graphic only to down sample it again. I don't currently know of a good way to render it at the "right" resolution in one IM command.
The order of the arguments matters! The -density X argument needs to go before image.eps because you want to affect the resolution that the input file is rendered at.
This is not super obvious in the manpage for convert, but is hinted at:
SYNOPSIS
convert [input-option] input-file [output-option] output-file
Maybe you should try it with -quality 100 -size "1024x1024", because resize often gives results that are ugly to view.
I have a YUV420 image of size 1280x720. I am trying to resize it to 720x576 using convert (Imagemagick) using below commandline options. But the generated output file doesnot seem to be a proper resized YUV420 image(I want the resized output also to be in YUV420 format):
convert -size 1280x720 -depth 8 -sampling-factor 2x2 test_1280x720_yuv420.yuv -filter lanczos -resize 720x576 -depth 8 -sampling-factor 2x2 720x576_yuv420.yuv //Here the output file size is not what it should be of a 720x576 YUV420 file which is 720x576x1.5 bytes.
Qiestion: What is the format of this output file then?
Also tried -sample option as, but same result. Incorrect sized output file. I even tried to display the generated resized file, but it sure is not a YUV420 file, as could not view it correctly at all.
convert -size 1280x720 -depth 8 -sampling-factor 2x2 test_1280x720_yuv420.yuv -sample 720x576 -depth 8 -sampling-factor 2x2 720x576_yuv420.yuv
Question: Would convert be able to do what I am trying to get done? IF yes, what are the options?
Question: Any other tool(freeware,shareware) which could help me resize YUV files(different formats YUV420, YUV444) to YUV format output files?
Try to ignore aspect ration!
Ignore Aspect Ratio ('!' flag)
If you want you can force "-resize" to ignore the aspect ratio and distort the image so it always generates an image exactly the size specified. This is done by adding the character '!' to the size. Unfortunately this character is also sometimes used for special purposes by various UNIX command line shells. So you may have to escape the character somehow to preserve it.
Example:
convert image.gif -resize 64x64\! resized_image.gif //Resized Image with ignore ratio option