Page 1 of 1

Need help upgrading script

Posted: 2019-10-03T15:29:40-07:00
by Flaver-D
imagemagick version ImageMagick-7.0.8-67-Q16-x64
Windows 10.0.18362 (build 18362)

Hi!
I'm currently working on bringing a script I wrote something like 10 years ago up to speed. Lets just say it's a bit of a mess so I'm hoping somebody has an idea on how to improve it.
The script is used to create index pages of a folder full of images that gets drag and dropped on the cmd file. While it still works, I want to improve it. One of the things that bugs me is that I would like each small picture to have just the name of the file under it without any extension. But I can't figure out how to do this.
Also, this one uses the old legacy apps and I would like to change that.
Here is my original script

Code: Select all

if "%~1" == "" goto error
rem Go to drag and drop folder
cd "%~1"

rem Get current dir name
for %%* in (.) do set CurrDirName=%%~n*

rem Count number of files in folder
for /f %%A in ('dir /a-d-s-h /b ^| find /v /c ""') do set cnt=%%A
echo File count = %cnt%

rem check if less or equal
if %cnt% leq 20 goto Small
rem check if less or equal
if %cnt% leq 30 goto Normal
rem check if greater than
if %cnt% geq 30 goto Big

:Small
echo small roll
Echo Creating thumbnails...
rem mogrify -format mpc -thumbnail 420 *.tif
mogrify -format mpc -thumbnail 620 *.jpg
Echo Creating index sheet... 
montage -units PixelsPerInch -density 300 ^
-tile 4x5 -label %%f -font Arial -pointsize 6 -background "white" ^
-fill "black" -geometry 620x630+2+2 ^
-auto-orient *.mpc -title "%CurrDirName%" "##contact large.mpc"
convert "##contact large.mpc" -gravity north -background white -extent 2550x3300 "contact large.jpg"
goto end

:error
cls
echo Please drag and drop a folder on this script
echo Thank you
pause
exit

:end
rem echo Cleaning up workplace...
del *.mpc
del *.cache
exit
I left out some bits which are just for different file counts... but you should be able to get the gist of it.

Thanks

Re: Need help upgrading script

Posted: 2019-10-03T15:49:25-07:00
by snibgo
The labels ":Normal" and ":Big" are mising. I suppose you have removed those sections for brevity.

You have "-label %%f". Perhaps you want %%t instead.

Re: Need help upgrading script

Posted: 2019-10-04T08:56:39-07:00
by Flaver-D
Thanks for the tip. The %%t is what was needed to get rid of the extension. I really wasn't aware of this switch before.
Yes, I did chop off those 2 labels so that I wouldn't overwhelm people with what is essentially redundant stuff.

Maybe I should have detailed what the script does in more detail.
I first check if a folder or individual files were dropped. Then if it was a folder, I count the number of files and select the proper layout for that number and start the image manipulation.
First I use mogrify to create a bunch of thumbnails using Imagemagick's own raw format.
Then I use montage to create a 300 DPI 4x5 thumbnail matrix with the folder name as a title and save in the default raw format.
Then I use convert to make the final image 8½"x 11" and save it as JPEG.
I finish by deleting the working raw files.

Is there a way to avoid doing the bunch of intermediate files without hogging memory too much?
I'd really love to bring this down to a single string if possible...