@ECHO OFF :: Script version SET MyVer=1.10 :: Windows NT 4 or later required IF NOT "%OS%"=="Windows_NT" GOTO Syntax :: Check if help is required IF NOT "%~1"=="" GOTO Syntax :: Localize variables SETLOCAL :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: Modify your settings below this line :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: SET Title=My Pictures SET FileSpec=*.jpg SET PictWidth=800 SET PictHeight=600 SET ThumbWidth=150 SET ThumbHeight=120 SET PhotoQuality=80 SET ThumbQuality=50 SET IndexCols=4 SET IndexRows=3 SET HomeURL=../index.html :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: Do not make any changes below this line :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: Use default values where none were specified IF NOT DEFINED FileSpec SET FileSpec=*.jpg IF NOT DEFINED PictWidth SET PictWidth=800 IF NOT DEFINED PictHeight SET PictHeight=600 IF NOT DEFINED ThumbWidth SET ThumbWidth=150 IF NOT DEFINED ThumbHeight SET ThumbHeight=120 IF NOT DEFINED PhotoQuality SET PhotoQuality=80 IF NOT DEFINED ThumbQuality SET ThumbQuality=50 IF NOT DEFINED IndexCols SET IndexCols=4 IF NOT DEFINED IndexRows SET IndexRows=3 IF NOT DEFINED HomeURL SET HomeURL=../index.html :: Check if irfanView is installed, and where START /WAIT REGEDIT.EXE /E "%Temp%.\i_view32_test.dat" "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\IrfanView" IF NOT EXIST "%Temp%.\i_view32_test.dat" GOTO Syntax FOR /F "tokens=2 delims==" %%A IN ('TYPE "%Temp%.\i_view32_test.dat" ^| FIND.EXE /I "UninstallString"') DO SET IView="%%~dpAi_view32.exe" DEL "%Temp%.\i_view32_test.dat" :: Create directory structure for web pages ( MD web MD web\jpgs MD web\thmb MD web\html ) >NUL 2>&1 :: Copy navigation buttons ( COPY "%~dp0first.gif" web\*.* COPY "%~dp0prev.gif" web\*.* COPY "%~dp0home.gif" web\*.* COPY "%~dp0index.gif" web\*.* COPY "%~dp0next.gif" web\*.* COPY "%~dp0last.gif" web\*.* ) >NUL 2>&1 :: Convert and compress photos, and create thumbnails ECHO Resizing and compressing pictures . . .>CON %IView% "%cd%\%FileSpec%" /resize=(%PictWidth%,%PictHeight%) /resample /aspectratio /convert="%cd%\web\jpgs\*.jpg" /jpgq=%PhotoQuality% ECHO Creating thumbnails . . .>CON %IView% "%cd%\%FileSpec%" /resize=(%ThumbWidth%,%ThumbHeight%) /resample /aspectratio /convert="%cd%\web\thmb\*.jpg" /jpgq=%ThumbQuality% FOR %%A IN ("%cd%\web\jpgs\*.jpg") DO REN "%cd%\web\thmb\%%~nxA" t_%%~nxA :: Get file name of first picture FOR /F "tokens=1* delims=[]" %%A IN ('DIR/A-D/B/O web\jpgs\*.jpg ^| FIND.EXE /N "." ^| FIND.EXE "[1]"') DO ( CALL SET FirstPic=%%~nB ) :: Get number and file name of last picture FOR /F "tokens=1* delims=[]" %%A IN ('DIR/A-D/B/O web\jpgs\*.jpg ^| FIND.EXE /N "."') DO ( CALL SET LastNum=%%A CALL SET LastPic=%%~nB ) :: Create an HTML page for each individual picture FOR /F "tokens=1* delims=[]" %%A IN ('DIR/A-D/B/O web\jpgs\*.jpg ^| FIND.EXE /N "."') DO ( CALL :CreateHTML %%A %%~nxB > web\%%~nB.html ) :: Create index pages CALL :CreateIndexPages :: Move all new files to a single directory and remove temporary directories ( MOVE web\jpgs\*.* web RD web\jpgs MOVE web\html\*.* web RD web\html MOVE web\thmb\*.* web RD web\thmb ) >NUL 2>&1 :: Show the result START web\index1.html :: End of main program ENDLOCAL GOTO:EOF :CreateHTML SET Num=%1 SET Pic=%~n2 ECHO Creating %Pic%.html . . .>CON SET /A PrevNum = %Num% - 1 SET /A NextNum = %Num% + 1 FOR /F "tokens=2 delims=[]" %%A IN ('DIR/A-D/B/O web\jpgs\*.jpg ^| FIND.EXE /N "." ^| FIND.EXE "[%PrevNum%]"') DO (SET PrevPic=%%~nA) IF %Num%==1 (SET PrevPic=) FOR /F "tokens=2 delims=[]" %%A IN ('DIR/A-D/B/O web\jpgs\*.jpg ^| FIND.EXE /N "." ^| FIND.EXE "[%NextNum%]"') DO (SET NextPic=%%~nA) IF %Num%==%LastNum% (SET NextPic=) SET /A PicsPerPage = %IndexCols% * %IndexRows% SET /A LastIndexNum = ( %LastNum% + %PicsPerPage% - 1 ) / %PicsPerPage% :: Write HTML page code ECHO ^ ECHO ^ ECHO ^ ECHO ^%Title% - %Pic% ^(%Num% of %LastNum%^)^ ECHO ^ ECHO ^ ECHO ^ ECHO. ECHO ^
ECHO. ECHO ^%Title% ^(%Num% of %LastNum%^)^ ECHO. ECHO ^^ ^ ECHO. CALL :CreateNavigationBar ECHO. ECHO ^ ECHO ^ ECHO ^^ ^ ECHO ^ ECHO ^ ECHO ^^%Pic%^ ECHO ^ ECHO ^ ECHO ^^ ^ ECHO ^ ECHO ^ ECHO ^%Pic%^ ECHO ^ ECHO ^ ECHO ^^ ^ ECHO ^ ECHO ^ ECHO. CALL :CreateNavigationBar ECHO. ECHO ^ ECHO. ECHO ^ ECHO ^ GOTO:EOF :CreateNavigationBar ECHO ^
ECHO ^ IF "%Num%"=="1" ( ECHO ^^ ^ ^ ^ ^ ECHO ^^ ^ ^ ^ ^ ) ELSE ( ECHO ^^^First^^ ECHO ^^^Previous^^ ) SET /A IndexNum = ( %Num% + %PicsPerPage% - 1 ) / %PicsPerPage% ECHO ^^^Index^^ IF "%Num%"=="%LastNum%" ( ECHO ^^ ^ ^ ^ ^ ECHO ^^ ^ ^ ^ ^ ) ELSE ( ECHO ^^^Next^^ ECHO ^^^Last^^ ) ECHO ^ ECHO ^ GOTO:EOF :CreateIndexPages IF %LastIndexNum% GTR 1 ( FOR /L %%I IN (1,1,%LastIndexNum%) DO (CALL :CreateIndex %%I > web\index%%I.html) ) ELSE ( CALL :CreateIndex 1 > web\index1.html ) GOTO:EOF :CreateIndex SET IndexNum=%1 SET IndexPage=index%IndexNum%.html ECHO Creating %IndexPage% . . .>CON :: Write HTML page code ECHO ^ ECHO ^ ECHO ^ ECHO ^%Title% ^(index %IndexNum% %IndexNum% of %LastIndexNum%^)^ ECHO ^ ECHO ^ ECHO ^ ECHO. ECHO ^
ECHO. ECHO ^%Title% ^(index %IndexNum% of %LastIndexNum%^)^ ECHO. ECHO ^^ ^ ECHO. CALL :CreateIndexNavBar ECHO. ECHO ^
SET /A StartNum = ( %IndexNum% - 1 ) * %PicsPerPage% FOR /L %%R IN (1,1,%IndexRows%) DO ( ECHO ^ FOR /L %%C IN (1,1,%IndexCols%) DO ( CALL :CreateIndexThumb %%R %%C %StartNum% ) ECHO ^ ) ECHO ^ ECHO. CALL :CreateIndexNavBar ECHO. ECHO ^ ECHO. ECHO ^ ECHO ^ GOTO:EOF :CreateIndexNavBar ECHO ^
ECHO ^ SET /A PrevIndex = %IndexNum% - 1 SET /A NextIndex = %IndexNum% + 1 IF "%IndexNum%"=="1" ( ECHO ^^ ^ ^ ^ ^ ECHO ^^ ^ ^ ^ ^ ) ELSE ( ECHO ^^^First^^ ECHO ^^^Previous^^ ) ECHO ^^^Home^^ IF "%IndexNum%"=="%LastIndexNum%" ( ECHO ^^ ^ ^ ^ ^ ECHO ^^ ^ ^ ^ ^ ) ELSE ( ECHO ^^^Next^^ ECHO ^^^Last^^ ) ECHO ^ ECHO ^ GOTO:EOF :CreateIndexThumb SET Row=%1 SET Col=%2 SET Offset=%3 SET /A IndexThumbNum = ( ( %Row% - 1 ) * %IndexCols% ) + %Col% SET /A ThumbNum = %IndexThumbNum% + %Offset% IF %ThumbNum% LEQ %LastNum% (SET Empty=0) ELSE (SET Empty=1) FOR /F "tokens=2 delims=[]" %%A IN ('DIR/A-D/B/O web\jpgs\*.jpg ^| FIND.EXE /N "." ^| FIND.EXE "[%ThumbNum%]"') DO (SET CurPic=%%~nA) IF %Empty%==0 ( ECHO ^
^^%CurPic%^^^^%CurPic%^^^ ) ELSE ( ECHO ^^ ^ ) GOTO:EOF :Syntax ECHO. ECHO Foto2Web.bat, Version %MyVer% for Windows NT 4 and later ECHO Generate HTML pages and indexes for all pictures in the current directory ECHO. ECHO Usage: FOTO2WEB ECHO. ECHO Notes: This batch file uses IrfanView to resize and compress pictures and ECHO to create thumbnails. ECHO IrfanView is available for download at http://www.irfanview.com/ ECHO The default settings for picture size and quality, and the index ECHO page layout will do for most people. However, you can modify them ECHO by changing the hard coded values near the top of this batch file. ECHO Read the comments in this batch file to locate these settings. ECHO Make sure the navigation "buttons" (GIFs) and this batch file are ECHO all located in the same directory. ECHO. ECHO Written by Rob van der Woude ECHO http://www.robvanderwoude.com ECHO. ECHO Updated for IrfanView 3.99 and later by Tim Smith SET MyVer=