Page 1 of 2

Multiple resize/rename on all files within directory

Posted: 2010-06-22T12:39:10-07:00
by TomC
Hello. I am new and have read the FAQs. Quite simply, I need help with command syntax please.

I am attempting to resize/rename all (25) .jpg files within a directory. Ideally, each resize set of files would go it's own sub dir. I don't want to lose the original file. I don't want to type in each file name either, Is there a way in IM command without doing a shell script? This is what I have tried:

1. convert Filename_1096_C3_%d.jpg[1-16] -shave 240x0 -resize 96x72 newthumbs/Filename_1096_c3r_%d.jpg[1-16] (no go)

2. mogrify -shave 240x0 -resize 96x72 *.jpg (this one works, but I need to copy to subdir first, then process on copied files.


I know this may be easy for most of you, but I am stuck.

Thanks in advance!

Re: Multiple resize/rename on all files within directory

Posted: 2010-06-22T14:58:20-07:00
by fmw42
mogrify is the best bet, but it works on one directory at a time.

otherwise, you will likely have to write a loop in a shell script to find all your files and then resize them where you want to place them.

Re: Multiple resize/rename on all files within directory

Posted: 2010-06-22T15:07:43-07:00
by snibgo
To put the outputs into directory xyz, try:

Code: Select all

mogrify -shave 240x0 -resize 96x72 -path xyz *.jpg
I get an error message with this, but only after it successfully creates the files.
mogrify: unable to open image `xyz\': No such file or directory @ error/blob.c/OpenBlob/2491.
mogrify: no decode delegate for this image format `xyz\' @ error/constitute.c/ReadImage/532.
Perhaps someone else can explain why I get the error.

Re: Multiple resize/rename on all files within directory

Posted: 2010-06-22T15:10:39-07:00
by fmw42
use the full path to the directory.

for example

create directory folder2 to hold new files
cd to directory folder1 which has the files

mogrify -path /Users/fred/folder2 -format jpg -shave 240x0 -resize 96x72 *.jpg

Re: Multiple resize/rename on all files within directory

Posted: 2010-06-22T15:22:30-07:00
by billbell52
You can use this windows batch script. Modify to meet your needs. Save as .bat file. Double click to execute.

rem convert dir of bmp images to black and white
set SOURCE=C:\userdata\bell\letters
set DESTDIR=C:\userdata\bell\batch
set DESTSUBDIR=
set SRCTYPE=bmp
set DESTTYPE=bmp
rem Following must be one line. No carriage returns.
for /r "%SOURCE%" %%X in ("*.%SRCTYPE%") do (if not exist "%DESTDIR%\%%~nX.%DESTTYPE%" (convert %%X -black-threshold "50%" -white-threshold "49%" %DESTDIR%\%%~nX.%DESTTYPE%) else (echo "Exists %DESTDIR%\%%~nX.%DESTTYPE%"))

Re: Multiple resize/rename on all files within directory

Posted: 2010-06-22T15:28:50-07:00
by snibgo
fmw42 wrote:use the full path to the directory.
Thanks, Fred. I tried with absolute paths, relative paths, with or without trailing slash, or using back-slash (the Windows convention). They all work, but all give the error.

Re: Multiple resize/rename on all files within directory

Posted: 2010-06-22T17:05:56-07:00
by fmw42
Thanks, Fred. I tried with absolute paths, relative paths, with or without trailing slash, or using back-slash (the Windows convention). They all work, but all give the error.
Check your file and folder permission.

What version of IM are you using. If old, then perhaps update. Or perhaps just reinstall. Something odd is happening on your system. What version of libjpg? If old, perhaps upgrade that too.

What platform are you on?

Re: Multiple resize/rename on all files within directory

Posted: 2010-06-22T18:31:21-07:00
by snibgo
Windows 7, IM 6.6.2-4.

No problem with permissions.

Code: Select all

md xyz
mogrify -path xyz tom.jpg
(Above works no problem.)

Code: Select all

mogrify -path xyz t*.jpg
mogrify: unable to open image `xyxxy\': No such file or directory @ error/blob.c/OpenBlob/2491.
mogrify: no decode delegate for this image format `xyxxy\' @ error/constitute.c/ReadImage/532.
mogrify: unable to open image `xyz\': No such file or directory @ error/blob.c/OpenBlob/2491.
mogrify: no decode delegate for this image format `xyz\' @ error/constitute.c/ReadImage/532.
As you might guess, this directory has two subdirectories: xyz and xyxxy.

The behaviour is the same when I use PNG files.

It is also the same when I omit "-path xyz". Oh dear, so the problem occurs with a trivial:

Code: Select all

mogrify t*.jpg
EDIT: the above problem is in Windows 7, IM 6.6.2-4 Q16.

The problem doesn't occur with IM 6.6.1-1 Q8 or 6.6.0-8 Q16.

Re: Multiple resize/rename on all files within directory

Posted: 2010-06-22T18:45:44-07:00
by snibgo
I've raised a bug report: viewtopic.php?f=3&t=16489

Re: Multiple resize/rename on all files within directory

Posted: 2010-06-23T08:07:28-07:00
by TomC
All,

Thanks for the prompt replies.

Adding the '-path' does help with moving the files.

I am still getting the error message even though the script seems to work.

Re: Multiple resize/rename on all files within directory

Posted: 2010-06-23T08:11:01-07:00
by snibgo
I am still getting the error message even though the script seems to work.
See the bug report. I expect this will be fixed in the next release.

Re: Multiple resize/rename on all files within directory

Posted: 2010-06-23T18:26:01-07:00
by anthony
Writing an Image, Multiple Times
http://www.imagemagick.org/Usage/files/#write

Then add this to a loop, such as...
Mogrify - Batch Processing Alternatives
http://www.imagemagick.org/Usage/basics/#mogrify_not

Re: Multiple resize/rename on all files within directory

Posted: 2010-06-24T18:54:14-07:00
by anthony
NOTE that mogrify can write an image multiple times using -write

For example....

Code: Select all

   mogrify -set filename:name %f -write '%[filename:name]_orig.gif' \
              -resize x800  -write '%[filename:name]_800.gif' \
              -resize x100  *.jpg
Of course the last resized image (100 pixels high) got saved into the ORIGINAL file name.
but a (read/write) copy was made first!

See IM examples, Filename Percent Escapes
http://www.imagemagick.org/Usage/files/#save_escapes

NOTE you must use a setting starting with filename: when writing filenames. this is for security concerns though input from ALL unknown source should be check anyway.

Re: Multiple resize/rename on all files within directory

Posted: 2011-02-04T07:27:41-07:00
by tg3793
Ok; well I thought it needed to be a little bit easier than this. Whether you do this on your home Linux desktop or a remote server doesn't matter (I did it on the latter).

Code: Select all

mogrify *.jpg -resize 10% *.jpg
The command above took about fifty images that were 2meg to 3meg each and converted them to images that were 90k to 150k in just a few seconds. All of the original images in the same directory were converted where they were ... Morgrify is great !

However I'd now like to stretch them to 640x480 since since they seem to all be about 420x360 (at the moment) or something similar ... I'm sure I'll dig up a switch around here somewhere for that :-)

Re: Multiple resize/rename on all files within directory

Posted: 2011-02-04T08:10:55-07:00
by tg3793
ah ... I found a better method

Code: Select all

mogrify *.jpg -quality 75 -resize "640x480>" *
This rocks !! :-)