Arranging images for printing - coming out higgledy-piggledy

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
seanspotatobusiness
Posts: 8
Joined: 2013-11-19T05:23:43-07:00
Authentication code: 6789

Arranging images for printing - coming out higgledy-piggledy

Post by seanspotatobusiness »

A friend of mine wrote the following batch file to automatically arrange my pictures for printing which is otherwise a tiresome chore. The process takes the images (of which there are five categories (I select among them when running the batch file) and arranges eight to each page, putting the name of each file underneath. The problem is that it doesn't seem to put the images in any clear order. Alphabetical order would be fine. Does anyone know whether this can be fixed?

Code: Select all

@echo off
setlocal EnableDelayedExpansion

echo 1 - Brightfield
echo 2 - B-R Merged
echo 3 - B-G Merged
echo 4 - UV red
echo 5 - UV green
set /p CHOICES=Type in the numbers (space delimited) of the types you want: 
echo.

set REGEX=%CHOICES%
set REGEX=%REGEX:1=^^^^.*Brightfield.*$ %
set REGEX=%REGEX:2=^^^^.*B-R.*$ %
set REGEX=%REGEX:3=^^^^.*B-G.*$ %
set REGEX=%REGEX:4=^^^^.*UV[ ]*red.*$ %
set REGEX=%REGEX:5=^^^^.*UV[ ]*green.*$ %

for /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set THEDATE=%%a-%%b)
for /f "tokens=1-2 delims=/:" %%a in ('time /t') do (set THETIME=%%a%%b)

set FILECOUNT=0
set n=0
set PAGENUM=
set PAGENUMPREFIX=

for /f "delims==" %%f in ('dir /b /s ^| findstr /r "%REGEX%"') do (
	set /a FILECOUNT+=1
)

if !FILECOUNT! gtr 8 (
	set PAGENUMPREFIX=_
	set PAGENUM=1
)

echo|set /p=Found !FILECOUNT! image(s), working... 

for /f "delims==" %%f in ('dir /b /s ^| findstr /r "%REGEX%"') do (
	convert "%%f" -pointsize 40 -size 1600x -gravity south -splice 0x150 -gravity south caption:"%%~nf" -composite "%%~nf_tmp%%~xf"
)

for /f "delims==" %%f in ('dir /b /s ^| findstr /r ".*_tmp\.tif$ .*_tmp\.tiff$"') do (
	set FILE=!FILE!"%%f" 
	set /a n+=1
	
	if !n! == 8 (
		montage !FILE! -tile x4 -geometry 1450x1450+75+0 -quiet "!THEDATE!_!THETIME!!PAGENUMPREFIX!!PAGENUM!".png
		convert "!THEDATE!_!THETIME!!PAGENUMPREFIX!!PAGENUM!".png -gravity center -extent 4960x7016 "!THEDATE!_!THETIME!!PAGENUMPREFIX!!PAGENUM!".png
		
		set n=0
		set /a PAGENUM+=1
		set FILE=
	)
)

if !n! gtr 0 (
	montage !FILE! -tile x4 -geometry 1450x1450+75+0 -quiet "!THEDATE!_!THETIME!!PAGENUMPREFIX!!PAGENUM!".png
	convert "!THEDATE!_!THETIME!!PAGENUMPREFIX!!PAGENUM!".png -gravity center -extent 4960x7016 "!THEDATE!_!THETIME!!PAGENUMPREFIX!!PAGENUM!".png
)

for /f "delims==" %%f in ('dir /b /s ^| findstr /r ".*_tmp\.tif$ .*_tmp\.tiff$"') do (
	del "%%f"
)

echo|set /p=done. 

if !PAGENUM! gtr 0 (
	echo !PAGENUM! pages created.
) else (
	echo 1 page created.
)
pause
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Arranging images for printing - coming out higgledy-pigg

Post by snibgo »

The obvious answer is to ask your friend. Ths is a scripting question, not specific to ImageMagick.

Which files do you want in alphabeical order? Perhaps the ones in ...

Code: Select all

    for /f "delims==" %%f in ('dir /b /s ^| findstr /r ".*_tmp\.tif$ .*_tmp\.tiff$"') do (
       set FILE=!FILE!"%%f"
       set /a n+=1
... etc       
If so, then adding a sort filter might do the job.

Code: Select all

    for /f "delims==" %%f in ('dir /b /s ^| sort ^| findstr /r ".*_tmp\.tif$ .*_tmp\.tiff$"') do (
       set FILE=!FILE!"%%f"
       set /a n+=1
... etc       
snibgo's IM pages: im.snibgo.com
Post Reply