I have multiple images stored in a set of organized folders. I need to re-size those images to a specific percentage recursively from their parent directory. I am running Ubuntu 11.10 and i prefer learning how to do that directly from the terminal.
相关问题
- Views base64 encoded blob in HTML with PHP
- How to get the background from multiple images by
- Why doesn't php sleep work in the windows-subs
- CV2 Image Error: error: (-215:Assertion failed) !s
- Installing Pydev for Eclipse throws error
相关文章
- 为什么nfs在不同版本的Linux下安装的文件都不一样
- Use savefig in Python with string and iterative in
- Where does this quality loss on Images come from?
- Specifying image dimensions in HTML vs CSS for pag
- How to insert pictures into each individual bar in
- How do I append metadata to an image in Matlab?
- Img url to dataurl using JavaScript
- Click an image, get coordinates
You can copy/paste this code in ubuntu, and save it as "resize.sh"
#!/bin/bash -e
CUR_DIR=`pwd`
cd $1
#resize
for file in *.jpg;
do
convert $file -resize 50% $file;
done
cd $CUR_DIR
After saving this file, run it from terminal using "./rotate.sh folder_containing_images"
For more such stuff, visit here
Extending the answer from @betabandido
Incase there are spaces in filenames or folder names in which the images are, then one should use -print0 with find and -0 with xargs to avoid any parsing errors.
It's also works if you give the new resize resolution :
You could use imagemagick. For instance, for resizing all the JPG images under the current directory to 50% of their original size, you could do:
The resulting files will have ".jpg" twice in their names. If that is an issue, you can check the following alternatives.
For traversing/finding the files to resize, you can use xargs too. Example:
This will create copies of the images. If you just want to convert them in place, you can use:
You can use imagemagick tool for batch resize.
It will maintain the aspect ratio
It will not maintain the aspect ratio
It will resize the image to 45x60 without maintaining the aspect ratio in current directory.
there are a few answers like:
this won't work as it will expand the list like this:
convert -resize 50% a.jpg b.jpg c.jpg
which will resizea.jpg
inc-0.jpg
,b.jpg
inc-1.jpg
and letc.jpg
untouched.So you have to execute the resize command for each match, and give both input file name and output file name, with something like:
each match of
find
is individually passed byxargs -n 1
to the resize script:sh -c 'convert -resize 50% $0 $(echo $0 | sed 's/\.jpg/-th\.jpg/')'
. This script receives the file name in argument$0
, usessed
to make an output file name by substitution of the original.jpg
suffix by a-th.jpg
one. And it runs theconvert
command with those two file names.Here is the version without
xargs
butfind -exec
: