ImageMagick has some pretty cool commandline tools to manage images. Specifically I wanted to resize an image (make it smaller).
convert -resize 50% -quality 80 input.jpg output.jpg |
You can change resize to a pixel size also: 800x600. Pretty handy and quick.
Update: You can resize/recompress and entire directory of images using find and xargs. This works good if you need to resize an entire directory/camera full of images to save space.
find . -iname "*.jpg" | xargs -l -i convert -quality 75 {} /tmp/output/{} |
Replies
find . -name "*.jpg" -exec convert -quality 75 {} /tmp/output/{} \;
achieves the same thing
find . -iname "*.jpg" | perl -e 'for(<>) { chomp $_;@a=split(/\//,$_);$str = "convert -resize 50% -quality 80 $_ thumbnails/".$a[-1];print $str."\n";`$str`}'
anyone knows that using xargs is much more effecient than using the -exec find flag.
also you can do:
for i in `ls *.jpg`; do convert -resize 50% -quality 80 $1 conv_$1; done
> also you can do:
> for i in `ls *.jpg`; do convert -resize 50% -quality 80 $1 conv_$1; done
$1 won't work at the end there, i think you mean to use $i like this:
for i in `ls *.jpg`; do convert -resize 50% -quality 80 $i conv_$i; done
How can I use the utility to dynamicly resize the images during display, i.e. in the perl code of my scipt that displays a dynamically created web page. I have hundreds of logos to display and I don't want to create additional copies for each display size. I just want to take the orginal 144x120px image and display it at 75% or so. IE and other browsers do a lousy job when you just tell them to display the 144x120 image at...say 120x100. They look like.....bad.
Surely you can just just do this:
convert * -resize 30x30 -quality 100 scaled.jpg
> > also you can do:
> > for i in `ls *.jpg`; do convert -resize 50% -quality 80 $1 conv_$1; done
> $1 won't work at the end there, i think you mean to use $i like this:
> for i in `ls *.jpg`; do convert -resize 50% -quality 80 $i conv_$i; done
I couldn't make this one work with filenames with spaces, even if i added -b flag to LS which escapes spaces (" " becomes "\ ").
However, if you want to list both JPG and jpg files, simply add both to the ls command, as such: "ls *.jpg *.JPG" and you'll list both types.
To answer a previous question, you can resize images on the fly using phpThumb. I works very well.
www.munkeefarm.com
Nice. Some comments and additional examples:
1. Use -print0 (and -0) to avoid problems with filenames containing Carriage Returns.
2. Use -maxdepth 0 to avoid descending into subdirectories. Use -maxdepth 1 to descend one level.
3. -i is deprecated for -I {}
4. -l is deprecated in preference for -L 1.
5. -I implies -L 1
find . -maxdepth 0 -iname "*.jpg" -print0 | xargs -0 -I {} convert -quality 75 {} /tmp/thumbs/{}
To compress and resize inplace:
NOTE! Mogrify is a dangerous command because it operates on the original files! Test your commands on COPIES of your files.
find . -maxdepth 0 -iname "*.jpg" -print0 | xargs -0 mogrify -resize 800x600 -quality 75
To change file types:
find . -maxdepth 0 -iname "*.jpg" -print0 | xargs -0 mogrify -format png
The above statement will leave the original JPG files alone, and write PNGs beside them.
To make PNG Thumbnails
*Before IM v6.3.4-3 the "-format" and "-path" settings were mutually exclusive. Upgrade if you need to use a different directory as well as a different image format for your output.
find . -maxdepth 0 -iname "*.jpg" -print0 | xargs -0 mogrify -path /tmp/thumbs -thumbnail 120x120 -quality 75 -format png
You don't need any complicated shell script to batch convert a whole directory of images - because ImageMagick's "convert" and "mogrify" commands support wildcards. (Aside: "convert" replaces existing files, "mogrify" allows you to specify an output file)
Here's an example of a single command that will create JPEG images at no larger than 640x480, setting the quality to 75 (pretty good). Notice the "-strip" option: This takes out JPEG's EXIF header data - which even in a small JPEG file can be 20,000 bytes of data! So it's a great idea to include this for web images, if you don't need all that EXIF data (and if you're like me, you probably didn't even know it existed, so you won't miss it right?)
mogrify -format jpg -quality 75 -resize "640x480>" -strip *
The wildcard "*" at the end means: Do all the files you find in this directory.
Enjoy :)
Can anyone help me out with this?
I want to convert and re-size my "artist/album/cover.png" images to smaller "artist/album/thumb.jpg" images.
The trick for me is to get all the converted images placed in the same folder as the original images..
After searching the net and trying things out, this is as far as I could get (and it doesn't work):
find . -iname '*.png' | xargs -0 -i convert -resize 100x100 {} ./*/*/thumb.jpg
I use imagemagick every single day, but I can't figure out how to make it make the resized images come out as crisp and colorfull as the originals :( Here is an example of what I use:
convert -size 640x480 'filename.jpg' -resize 640x480 profile "*" -quality 100 -auto-orient 'newfilename.jpg'
The images tend to come out soft and somewhat desaturated.
Any ideas on how to fix that?