Page 1 of 1

resize and rename a folder of images

Posted: 2013-07-01T21:00:38-07:00
by geomcd
Using Ubuntu Linux 12.04 LTS, I want to resize a folder of images and also rename those images in sequence. That is, the folder contains (only) images numbered in sequence named IMG_0545.jpg to IMG_0742.jpg. The images are all 4288x2848. I want to resize them all to 1000x664, and rename them, sequentially, that is, campus1.jpg, campus2.jpg, etc.

Thanks very much.

~George

Re: resize and rename a folder of images

Posted: 2013-07-01T21:07:23-07:00
by fmw42
I think you will have to write a script loop to loop over all the files in the directory and use convert to resize and rename them. Mogrify will resize them just fine, but I do not believe you can renumber them in that tool.

If you have too many large files, then convert may not work well as it may have to swap to disk if you do not have enough memory to hold them all and their resized images. Convert always loads all the images first.

Mogrify is better as it process each image one at a time. But I do not know how you would automatically renumber them.

Thus to avoid loading all the images in memory with convert, you need to script a loop over all the files you want so that it does one convert for each image.

something like

cd to directory
list=`ls`
i=1
for image in $list; do
convert $image -resize 1000x664 campus$i.jpg
i=$((i+1))
done

Note however if the input image aspect ratio is not the same as 1000:664, then you will not get exactly 1000x664. But your 4288x2848 does seem to have the same aspect ratio. So you should be fine.

see
http://www.imagemagick.org/Usage/basics/#mogrify
http://www.imagemagick.org/Usage/basics/#mogrify_not
http://www.imagemagick.org/script/comma ... p#geometry

Re: resize and rename a folder of images

Posted: 2013-07-02T09:12:57-07:00
by glennrp
I would create a simple shell script to do the renaming and numbering, and after running that, use "mogrify -resize WxH *.jpg" to resize them.

Re: resize and rename a folder of images

Posted: 2013-07-07T20:58:58-07:00
by anthony
renumbering file is best done using a different tool.

For example I have a script "mv_renum" which replaces numbers in filenames with a fix length numbers.
By default the longest number of digits found, but yu can specify number of digits with an option.

If the same program is named (or link from) "mv_reseq" it will re-order the files to remove number gaps.
or leave regular gaps (so say all file numbers increment by 5). It does this so as to not overwrite any files.

Another 'perl' based script "mv_perl" can do similar (but less versite with respect to numbers) but it can do a lot more such as: substitute strings, lowercase, uppercase, replace spaces capitalise words, space out words, etc.

See my software export
http://www.ict.griffith.edu.au/anthony/ ... /#mv_renum

Of course this assumes a UNIX-like environment (linux, mac, cygwin)