Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for foto2web.bat

(view source code of foto2web.bat as plain text)

  1. @ECHO OFF
  2. :: Script version
  3. SET MyVer=1.10
  4.  
  5. :: Windows NT 4 or later required
  6. IF NOT "%OS%"=="Windows_NT" GOTO Syntax
  7.  
  8. :: Check if help is required
  9. IF NOT "%~1"=="" GOTO Syntax
  10.  
  11. :: Localize variables
  12. SETLOCAL
  13.  
  14.  
  15. :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: ::
  16. :: :: :: :: :: :: :: :: Modify your settings below this line   :: :: :: :: :: :: :: ::
  17. :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: ::
  18.  
  19. 	SET Title=My Pictures
  20. 	SET FileSpec=*.jpg
  21. 	SET PictWidth=800
  22. 	SET PictHeight=600
  23. 	SET ThumbWidth=150
  24. 	SET ThumbHeight=120
  25. 	SET PhotoQuality=80
  26. 	SET ThumbQuality=50
  27. 	SET IndexCols=4
  28. 	SET IndexRows=3
  29. 	SET HomeURL=../index.html
  30.  
  31. :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: ::
  32. :: :: :: :: :: :: :: :: Do not make any changes below this line   :: :: :: :: :: :: ::
  33. :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: :: ::
  34.  
  35.  
  36. :: Use default values where none were specified
  37. IF NOT DEFINED FileSpec     SET FileSpec=*.jpg
  38. IF NOT DEFINED PictWidth    SET PictWidth=800
  39. IF NOT DEFINED PictHeight   SET PictHeight=600
  40. IF NOT DEFINED ThumbWidth   SET ThumbWidth=150
  41. IF NOT DEFINED ThumbHeight  SET ThumbHeight=120
  42. IF NOT DEFINED PhotoQuality SET PhotoQuality=80
  43. IF NOT DEFINED ThumbQuality SET ThumbQuality=50
  44. IF NOT DEFINED IndexCols    SET IndexCols=4
  45. IF NOT DEFINED IndexRows    SET IndexRows=3
  46. IF NOT DEFINED HomeURL      SET HomeURL=../index.html
  47.  
  48. :: Check if irfanView is installed, and where
  49. START /WAIT REGEDIT.EXE /E "%Temp%.\i_view32_test.dat" "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\IrfanView"
  50. IF NOT EXIST "%Temp%.\i_view32_test.dat" GOTO Syntax
  51. FOR /F "tokens=2 delims==" %%A IN ('TYPE "%Temp%.\i_view32_test.dat" ^| FIND.EXE /I "UninstallString"') DO SET IView="%%~dpAi_view32.exe"
  52. DEL "%Temp%.\i_view32_test.dat"
  53.  
  54. :: Create directory structure for web pages
  55. (
  56. 	MD web
  57. 	MD web\jpgs
  58. 	MD web\thmb
  59. 	MD web\html
  60. ) >NUL 2>&1
  61.  
  62. :: Copy navigation buttons
  63. (
  64. 	COPY "%~dp0first.gif" web\*.*
  65. 	COPY "%~dp0prev.gif"  web\*.*
  66. 	COPY "%~dp0home.gif"  web\*.*
  67. 	COPY "%~dp0index.gif" web\*.*
  68. 	COPY "%~dp0next.gif"  web\*.*
  69. 	COPY "%~dp0last.gif"  web\*.*
  70. ) >NUL 2>&1
  71.  
  72. :: Convert and compress photos, and create thumbnails
  73. ECHO Resizing and compressing pictures . . .>CON
  74. %IView% "%cd%\%FileSpec%" /resize=(%PictWidth%,%PictHeight%) /resample /aspectratio /convert="%cd%\web\jpgs\*.jpg" /jpgq=%PhotoQuality%
  75. ECHO Creating thumbnails . . .>CON
  76. %IView% "%cd%\%FileSpec%" /resize=(%ThumbWidth%,%ThumbHeight%) /resample /aspectratio /convert="%cd%\web\thmb\*.jpg" /jpgq=%ThumbQuality%
  77. FOR %%A IN ("%cd%\web\jpgs\*.jpg") DO REN "%cd%\web\thmb\%%~nxA" t_%%~nxA
  78.  
  79. :: Get file name of first picture
  80. FOR /F "tokens=1* delims=[]" %%A IN ('DIR/A-D/B/O web\jpgs\*.jpg ^| FIND.EXE /N "." ^| FIND.EXE "[1]"') DO (
  81. 	CALL SET FirstPic=%%~nB
  82. )
  83.  
  84. :: Get number and file name of last picture
  85. FOR /F "tokens=1* delims=[]" %%A IN ('DIR/A-D/B/O web\jpgs\*.jpg ^| FIND.EXE /N "."') DO (
  86. 	CALL SET LastNum=%%A
  87. 	CALL SET LastPic=%%~nB
  88. )
  89.  
  90. :: Create an HTML page for each individual picture
  91. FOR /F "tokens=1* delims=[]" %%A IN ('DIR/A-D/B/O web\jpgs\*.jpg ^| FIND.EXE /N "."') DO (
  92. 	CALL :CreateHTML %%A %%~nxB > web\%%~nB.html
  93. )
  94.  
  95. :: Create index pages
  96. CALL :CreateIndexPages
  97.  
  98. :: Move all new files to a single directory and remove temporary directories
  99. (
  100. 	MOVE web\jpgs\*.* web
  101. 	RD   web\jpgs
  102. 	MOVE web\html\*.* web
  103. 	RD   web\html
  104. 	MOVE web\thmb\*.* web
  105. 	RD   web\thmb
  106. ) >NUL 2>&1
  107.  
  108. :: Show the result
  109. START web\index1.html
  110.  
  111. :: End of main program
  112. ENDLOCAL
  113. GOTO:EOF
  114.  
  115.  
  116. :CreateHTML
  117. SET Num=%1
  118. SET Pic=%~n2
  119. ECHO Creating %Pic%.html . . .>CON
  120. SET /A PrevNum = %Num% - 1
  121. SET /A NextNum = %Num% + 1
  122. 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)
  123. IF %Num%==1 (SET PrevPic=)
  124. 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)
  125. IF %Num%==%LastNum% (SET NextPic=)
  126. SET /A PicsPerPage  = %IndexCols% * %IndexRows%
  127. SET /A LastIndexNum = ( %LastNum% + %PicsPerPage% - 1 ) / %PicsPerPage%
  128. :: Write HTML page code
  129. ECHO ^<!DOCTYPE HTML PUBLIC "-//IW3C//DTD HTML 3.2//EN"^>
  130. ECHO ^<HTML^>
  131. ECHO ^<HEAD^>
  132. ECHO ^<TITLE^>%Title% - %Pic% ^(%Num% of %LastNum%^)^</TITLE^>
  133. ECHO ^<META NAME="generator" CONTENT="Foto2Web.bat, Version %MyVer%, by Rob van der Woude, http://www.robvanderwoude.com, and IrfanView, http://www.irfanview.com"^>
  134. ECHO ^</HEAD^>
  135. ECHO ^<BODY BGCOLOR="White" TEXT="Black" LINK="Green" VLINK="Magenta" ALINK="Blue"^>
  136. ECHO.
  137. ECHO ^<DIV ALIGN="center"^>
  138. ECHO.
  139. ECHO ^<H1^>%Title% ^(%Num% of %LastNum%^)^</H1^>
  140. ECHO.
  141. ECHO ^<P^>^&nbsp;^</P^>
  142. ECHO.
  143. CALL :CreateNavigationBar
  144. ECHO.
  145. ECHO ^<TABLE BORDER="0" CELLSPACING="5"^>
  146. ECHO ^<TR^>
  147. ECHO     ^<TD^>^&nbsp;^</TD^>
  148. ECHO ^</TR^>
  149. ECHO ^<TR^>
  150. ECHO     ^<TD^>^<IMG SRC="%Pic%.jpg" BORDER="0" ALT="%Pic%"^>^</TD^>
  151. ECHO ^</TR^>
  152. ECHO ^<TR^>
  153. ECHO     ^<TD^>^&nbsp;^</TD^>
  154. ECHO ^</TR^>
  155. ECHO ^<TR^>
  156. ECHO     ^<TH^>%Pic%^</TH^>
  157. ECHO ^</TR^>
  158. ECHO ^<TR^>
  159. ECHO     ^<TD^>^&nbsp;^</TD^>
  160. ECHO ^</TR^>
  161. ECHO ^</TABLE^>
  162. ECHO.
  163. CALL :CreateNavigationBar
  164. ECHO.
  165. ECHO ^</DIV^>
  166. ECHO.
  167. ECHO ^</BODY^>
  168. ECHO ^</HTML^>
  169. GOTO:EOF
  170.  
  171.  
  172. :CreateNavigationBar
  173. ECHO ^<TABLE BORDER="0" CELLSPACING="5"^>
  174. ECHO ^<TR^>
  175. IF "%Num%"=="1" (
  176. 	ECHO     ^<TD^>^&nbsp;^&nbsp;^&nbsp;^&nbsp;^</TD^>
  177. 	ECHO     ^<TD^>^&nbsp;^&nbsp;^&nbsp;^&nbsp;^</TD^>
  178. ) ELSE (
  179. 	ECHO     ^<TD^>^<A HREF="%FirstPic%.html"^>^<IMG SRC="first.gif" BORDER="0" ALT="First"^>^</A^>^</TD^>
  180. 	ECHO     ^<TD^>^<A HREF="%PrevPic%.html"^>^<IMG SRC="prev.gif" BORDER="0" ALT="Previous"^>^</A^>^</TD^>
  181. )
  182. SET /A IndexNum = ( %Num% + %PicsPerPage% - 1 ) / %PicsPerPage%
  183. ECHO     ^<TD^>^<A HREF="index%IndexNum%.html"^>^<IMG SRC="index.gif" BORDER="0" ALT="Index"^>^</A^>^</TD^>
  184. IF "%Num%"=="%LastNum%" (
  185. 	ECHO     ^<TD^>^&nbsp;^&nbsp;^&nbsp;^&nbsp;^</TD^>
  186. 	ECHO     ^<TD^>^&nbsp;^&nbsp;^&nbsp;^&nbsp;^</TD^>
  187. ) ELSE (
  188. 	ECHO     ^<TD^>^<A HREF="%NextPic%.html"^>^<IMG SRC="next.gif" BORDER="0" ALT="Next"^>^</A^>^</TD^>
  189. 	ECHO     ^<TD^>^<A HREF="%LastPic%.html"^>^<IMG SRC="last.gif" BORDER="0" ALT="Last"^>^</A^>^</TD^>
  190. )
  191. ECHO ^</TR^>
  192. ECHO ^</TABLE^>
  193. GOTO:EOF
  194.  
  195.  
  196. :CreateIndexPages
  197. IF %LastIndexNum% GTR 1 (
  198. 	FOR /L %%I IN (1,1,%LastIndexNum%) DO (CALL :CreateIndex %%I > web\index%%I.html)
  199. ) ELSE (
  200. 	CALL :CreateIndex 1 > web\index1.html
  201. )
  202. GOTO:EOF
  203.  
  204.  
  205. :CreateIndex
  206. SET IndexNum=%1
  207. SET IndexPage=index%IndexNum%.html
  208. ECHO Creating %IndexPage% . . .>CON
  209. :: Write HTML page code
  210. ECHO ^<!DOCTYPE HTML PUBLIC "-//IW3C//DTD HTML 3.2//EN"^>
  211. ECHO ^<HTML^>
  212. ECHO ^<HEAD^>
  213. ECHO ^<TITLE^>%Title% ^(index %IndexNum% %IndexNum% of %LastIndexNum%^)^</TITLE^>
  214. ECHO ^<META NAME="generator" CONTENT="Foto2Web.bat, Version %MyVer%, by Rob van der Woude, http://www.robvanderwoude.com, and IrfanView, http://www.irfanview.com"^>
  215. ECHO ^</HEAD^>
  216. ECHO ^<BODY BGCOLOR="White" TEXT="Black" LINK="Green" VLINK="Magenta" ALINK="Blue"^>
  217. ECHO.
  218. ECHO ^<DIV ALIGN="center"^>
  219. ECHO.
  220. ECHO ^<H1^>%Title% ^(index %IndexNum% of %LastIndexNum%^)^</H1^>
  221. ECHO.
  222. ECHO ^<P^>^&nbsp;^</P^>
  223. ECHO.
  224. CALL :CreateIndexNavBar
  225. ECHO.
  226. ECHO ^<TABLE BORDER="0" CELLSPACING="50"^>
  227. SET /A StartNum = ( %IndexNum% - 1 ) * %PicsPerPage%
  228. FOR /L %%R IN (1,1,%IndexRows%) DO (
  229. 	ECHO ^<TR^>
  230. 	FOR /L %%C IN (1,1,%IndexCols%) DO (
  231. 		CALL :CreateIndexThumb %%R %%C %StartNum%
  232. 	)
  233. 	ECHO ^</TR^>
  234. )
  235. ECHO ^</TABLE^>
  236. ECHO.
  237. CALL :CreateIndexNavBar
  238. ECHO.
  239. ECHO ^</DIV^>
  240. ECHO.
  241. ECHO ^</BODY^>
  242. ECHO ^</HTML^>
  243. GOTO:EOF
  244.  
  245.  
  246. :CreateIndexNavBar
  247. ECHO ^<TABLE BORDER="0" CELLSPACING="5"^>
  248. ECHO ^<TR^>
  249. SET /A PrevIndex = %IndexNum% - 1
  250. SET /A NextIndex = %IndexNum% + 1
  251. IF "%IndexNum%"=="1" (
  252. 	ECHO     ^<TD^>^&nbsp;^&nbsp;^&nbsp;^&nbsp;^</TD^>
  253. 	ECHO     ^<TD^>^&nbsp;^&nbsp;^&nbsp;^&nbsp;^</TD^>
  254. ) ELSE (
  255. 	ECHO     ^<TD^>^<A HREF="index1.html"^>^<IMG SRC="first.gif" BORDER="0" ALT="First"^>^</A^>^</TD^>
  256. 	ECHO     ^<TD^>^<A HREF="index%PrevIndex%.html"^>^<IMG SRC="prev.gif" BORDER="0" ALT="Previous"^>^</A^>^</TD^>
  257. )
  258. ECHO     ^<TD^>^<A HREF="%HomeURL%"^>^<IMG SRC="home.gif" BORDER="0" ALT="Home"^>^</A^>^</TD^>
  259. IF "%IndexNum%"=="%LastIndexNum%" (
  260. 	ECHO     ^<TD^>^&nbsp;^&nbsp;^&nbsp;^&nbsp;^</TD^>
  261. 	ECHO     ^<TD^>^&nbsp;^&nbsp;^&nbsp;^&nbsp;^</TD^>
  262. ) ELSE (
  263. 	ECHO     ^<TD^>^<A HREF="index%NextIndex%.html"^>^<IMG SRC="next.gif" BORDER="0" ALT="Next"^>^</A^>^</TD^>
  264. 	ECHO     ^<TD^>^<A HREF="index%LastIndexNum%.html"^>^<IMG SRC="last.gif" BORDER="0" ALT="Last"^>^</A^>^</TD^>
  265. )
  266. ECHO ^</TR^>
  267. ECHO ^</TABLE^>
  268. GOTO:EOF
  269.  
  270.  
  271. :CreateIndexThumb
  272. SET Row=%1
  273. SET Col=%2
  274. SET Offset=%3
  275. SET /A IndexThumbNum = ( ( %Row% - 1 ) * %IndexCols% ) + %Col%
  276. SET /A ThumbNum = %IndexThumbNum% + %Offset%
  277. IF %ThumbNum% LEQ %LastNum% (SET Empty=0) ELSE (SET Empty=1)
  278. 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)
  279. IF %Empty%==0 (
  280. 	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^>
  281. ) ELSE (
  282. 	ECHO     ^<TD^>^&nbsp;^</TD^>
  283. )
  284. GOTO:EOF
  285.  
  286.  
  287. :Syntax
  288. ECHO.
  289. ECHO Foto2Web.bat, Version %MyVer% for Windows NT 4 and later
  290. ECHO Generate HTML pages and indexes for all pictures in the current directory
  291. ECHO.
  292. ECHO Usage:  FOTO2WEB
  293. ECHO.
  294. ECHO Notes:  This batch file uses IrfanView to resize and compress pictures and
  295. ECHO         to create thumbnails.
  296. ECHO         IrfanView is available for download at http://www.irfanview.com/
  297. ECHO         The default settings for picture size and quality, and the index
  298. ECHO         page layout will do for most people. However, you can modify them
  299. ECHO         by changing the hard coded values near the top of this batch file.
  300. ECHO         Read the comments in this batch file to locate these settings.
  301. ECHO         Make sure the navigation "buttons" (GIFs) and this batch file are
  302. ECHO         all located in the same directory.
  303. ECHO.
  304. ECHO Written by Rob van der Woude
  305. ECHO http://www.robvanderwoude.com
  306. ECHO.
  307. ECHO Updated for IrfanView 3.99 and later by Tim Smith
  308. SET MyVer=
  309.  

page last uploaded: 2017-08-21, 14:26