Multiple resize/rename on all files within directory
Multiple resize/rename on all files within directory
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!
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!
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Multiple resize/rename on all files within directory
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.
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.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Multiple resize/rename on all files within directory
To put the outputs into directory xyz, try:
I get an error message with this, but only after it successfully creates the files.
Code: Select all
mogrify -shave 240x0 -resize 96x72 -path xyz *.jpg
Perhaps someone else can explain why I get the error.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.
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Multiple resize/rename on all files within directory
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
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
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%"))
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%"))
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Multiple resize/rename on all files within 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.fmw42 wrote:use the full path to the directory.
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Multiple resize/rename on all files within directory
Check your file and folder permission.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.
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?
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Multiple resize/rename on all files within directory
Windows 7, IM 6.6.2-4.
No problem with permissions.
(Above works no problem.)
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:
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.
No problem with permissions.
Code: Select all
md xyz
mogrify -path xyz tom.jpg
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.
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
The problem doesn't occur with IM 6.6.1-1 Q8 or 6.6.0-8 Q16.
snibgo's IM pages: im.snibgo.com
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Multiple resize/rename on all files within directory
I've raised a bug report: viewtopic.php?f=3&t=16489
snibgo's IM pages: im.snibgo.com
Re: Multiple resize/rename on all files within directory
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.
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.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Multiple resize/rename on all files within directory
See the bug report. I expect this will be fixed in the next release.I am still getting the error message even though the script seems to work.
snibgo's IM pages: im.snibgo.com
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Multiple resize/rename on all files within directory
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
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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Multiple resize/rename on all files within directory
NOTE that mogrify can write an image multiple times using -write
For example....
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.
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
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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Multiple resize/rename on all files within directory
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).
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
Code: Select all
mogrify *.jpg -resize 10% *.jpg
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
ah ... I found a better method
This rocks !!
Code: Select all
mogrify *.jpg -quality 75 -resize "640x480>" *