(view source code of foto2web.bat as plain text)
@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 ^<!DOCTYPE HTML PUBLIC "-//IW3C//DTD HTML 3.2//EN"^>
ECHO ^<HTML^>
ECHO ^<HEAD^>
ECHO ^<TITLE^>%Title% - %Pic% ^(%Num% of %LastNum%^)^</TITLE^>
ECHO ^<META NAME="generator" CONTENT="Foto2Web.bat, Version %MyVer%, by Rob van der Woude, http://www.robvanderwoude.com, and IrfanView, http://www.irfanview.com"^>
ECHO ^</HEAD^>
ECHO ^<BODY BGCOLOR="White" TEXT="Black" LINK="Green" VLINK="Magenta" ALINK="Blue"^>
ECHO.
ECHO ^<DIV ALIGN="center"^>
ECHO.
ECHO ^<H1^>%Title% ^(%Num% of %LastNum%^)^</H1^>
ECHO.
ECHO ^<P^>^ ^</P^>
ECHO.
CALL :CreateNavigationBar
ECHO.
ECHO ^<TABLE BORDER="0" CELLSPACING="5"^>
ECHO ^<TR^>
ECHO ^<TD^>^ ^</TD^>
ECHO ^</TR^>
ECHO ^<TR^>
ECHO ^<TD^>^<IMG SRC="%Pic%.jpg" BORDER="0" ALT="%Pic%"^>^</TD^>
ECHO ^</TR^>
ECHO ^<TR^>
ECHO ^<TD^>^ ^</TD^>
ECHO ^</TR^>
ECHO ^<TR^>
ECHO ^<TH^>%Pic%^</TH^>
ECHO ^</TR^>
ECHO ^<TR^>
ECHO ^<TD^>^ ^</TD^>
ECHO ^</TR^>
ECHO ^</TABLE^>
ECHO.
CALL :CreateNavigationBar
ECHO.
ECHO ^</DIV^>
ECHO.
ECHO ^</BODY^>
ECHO ^</HTML^>
GOTO:EOF
:CreateNavigationBar
ECHO ^<TABLE BORDER="0" CELLSPACING="5"^>
ECHO ^<TR^>
IF "%Num%"=="1" (
ECHO ^<TD^>^ ^ ^ ^ ^</TD^>
ECHO ^<TD^>^ ^ ^ ^ ^</TD^>
) ELSE (
ECHO ^<TD^>^<A HREF="%FirstPic%.html"^>^<IMG SRC="first.gif" BORDER="0" ALT="First"^>^</A^>^</TD^>
ECHO ^<TD^>^<A HREF="%PrevPic%.html"^>^<IMG SRC="prev.gif" BORDER="0" ALT="Previous"^>^</A^>^</TD^>
)
SET /A IndexNum = ( %Num% + %PicsPerPage% - 1 ) / %PicsPerPage%
ECHO ^<TD^>^<A HREF="index%IndexNum%.html"^>^<IMG SRC="index.gif" BORDER="0" ALT="Index"^>^</A^>^</TD^>
IF "%Num%"=="%LastNum%" (
ECHO ^<TD^>^ ^ ^ ^ ^</TD^>
ECHO ^<TD^>^ ^ ^ ^ ^</TD^>
) ELSE (
ECHO ^<TD^>^<A HREF="%NextPic%.html"^>^<IMG SRC="next.gif" BORDER="0" ALT="Next"^>^</A^>^</TD^>
ECHO ^<TD^>^<A HREF="%LastPic%.html"^>^<IMG SRC="last.gif" BORDER="0" ALT="Last"^>^</A^>^</TD^>
)
ECHO ^</TR^>
ECHO ^</TABLE^>
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 ^<!DOCTYPE HTML PUBLIC "-//IW3C//DTD HTML 3.2//EN"^>
ECHO ^<HTML^>
ECHO ^<HEAD^>
ECHO ^<TITLE^>%Title% ^(index %IndexNum% %IndexNum% of %LastIndexNum%^)^</TITLE^>
ECHO ^<META NAME="generator" CONTENT="Foto2Web.bat, Version %MyVer%, by Rob van der Woude, http://www.robvanderwoude.com, and IrfanView, http://www.irfanview.com"^>
ECHO ^</HEAD^>
ECHO ^<BODY BGCOLOR="White" TEXT="Black" LINK="Green" VLINK="Magenta" ALINK="Blue"^>
ECHO.
ECHO ^<DIV ALIGN="center"^>
ECHO.
ECHO ^<H1^>%Title% ^(index %IndexNum% of %LastIndexNum%^)^</H1^>
ECHO.
ECHO ^<P^>^ ^</P^>
ECHO.
CALL :CreateIndexNavBar
ECHO.
ECHO ^<TABLE BORDER="0" CELLSPACING="50"^>
SET /A StartNum = ( %IndexNum% - 1 ) * %PicsPerPage%
FOR /L %%R IN (1,1,%IndexRows%) DO (
ECHO ^<TR^>
FOR /L %%C IN (1,1,%IndexCols%) DO (
CALL :CreateIndexThumb %%R %%C %StartNum%
)
ECHO ^</TR^>
)
ECHO ^</TABLE^>
ECHO.
CALL :CreateIndexNavBar
ECHO.
ECHO ^</DIV^>
ECHO.
ECHO ^</BODY^>
ECHO ^</HTML^>
GOTO:EOF
:CreateIndexNavBar
ECHO ^<TABLE BORDER="0" CELLSPACING="5"^>
ECHO ^<TR^>
SET /A PrevIndex = %IndexNum% - 1
SET /A NextIndex = %IndexNum% + 1
IF "%IndexNum%"=="1" (
ECHO ^<TD^>^ ^ ^ ^ ^</TD^>
ECHO ^<TD^>^ ^ ^ ^ ^</TD^>
) ELSE (
ECHO ^<TD^>^<A HREF="index1.html"^>^<IMG SRC="first.gif" BORDER="0" ALT="First"^>^</A^>^</TD^>
ECHO ^<TD^>^<A HREF="index%PrevIndex%.html"^>^<IMG SRC="prev.gif" BORDER="0" ALT="Previous"^>^</A^>^</TD^>
)
ECHO ^<TD^>^<A HREF="%HomeURL%"^>^<IMG SRC="home.gif" BORDER="0" ALT="Home"^>^</A^>^</TD^>
IF "%IndexNum%"=="%LastIndexNum%" (
ECHO ^<TD^>^ ^ ^ ^ ^</TD^>
ECHO ^<TD^>^ ^ ^ ^ ^</TD^>
) ELSE (
ECHO ^<TD^>^<A HREF="index%NextIndex%.html"^>^<IMG SRC="next.gif" BORDER="0" ALT="Next"^>^</A^>^</TD^>
ECHO ^<TD^>^<A HREF="index%LastIndexNum%.html"^>^<IMG SRC="last.gif" BORDER="0" ALT="Last"^>^</A^>^</TD^>
)
ECHO ^</TR^>
ECHO ^</TABLE^>
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 ^<TD ALIGN="center"^>^<A HREF="%CurPic%.html"^>^<IMG SRC="t_%CurPic%.jpg" BORDER="0" ALT="%CurPic%"^>^</A^>^<BR^>^<B^>^<FONT SIZE="+2"^>%CurPic%^</FONT^>^</B^>^</TD^>
) ELSE (
ECHO ^<TD^>^ ^</TD^>
)
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=
page last modified: 2024-04-16; loaded in 0.0174 seconds