source: extensions/BuildPWGPicture/BuildPWGPicture.cmd @ 17079

Last change on this file since 17079 was 8425, checked in by rub, 14 years ago

Happy new year!

Change header of maintained extensions

File size: 10.5 KB
Line 
1@echo off
2rem ~ +-----------------------------------------------------------------------+
3rem ~ | BuildPWGPicture - a Windows batch command for Piwigo                  |
4rem ~ | Copyright (C) 2007-2011 Ruben ARNAUD - rub@piwigo.org                 |
5rem ~ +-----------------------------------------------------------------------+
6rem ~ | Version: 1.0.6.0                                                      |
7rem ~ +-----------------------------------------------------------------------+
8rem ~ | This program is free software; you can redistribute it and/or modify  |
9rem ~ | it under the terms of the GNU General Public License as published by  |
10rem ~ | the Free Software Foundation                                          |
11rem ~ |                                                                       |
12rem ~ | This program is distributed in the hope that it will be useful, but   |
13rem ~ | WITHOUT ANY WARRANTY; without even the implied warranty of            |
14rem ~ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
15rem ~ | General Public License for more details.                              |
16rem ~ |                                                                       |
17rem ~ | You should have received a copy of the GNU General Public License     |
18rem ~ | along with this program; if not, write to the Free Software           |
19rem ~ | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
20rem ~ | USA.                                                                  |
21rem ~ +-----------------------------------------------------------------------+
22
23set DirName=
24rem ~ parameter "~" remove """
25set argv1=%~1
26if not defined argv1 goto :not_argv1_dirname
27if "%argv1:~0,1%" == "-" goto :not_argv1_dirname
28set DirName=%argv1%
29shift /1
30:not_argv1_dirname
31
32rem ~ %* don't change with shift
33rem ~ on dos, there are only 9 max args
34set all_args=%1 %2 %3 %4 %5 %6 %7 %8 %9
35
36rem ~ undefined parameters
37set DirSrc=
38set DirDest=
39set ParFile=
40
41rem ~ Default parameters
42set DirXnView=C:\Program Files\XnView
43set DirAlbum=F:\Album
44set DirFTP=C:\Docume~1\Ruben\Bureau\FTP
45set GlobalCvtOpt=-opthuff -i
46set ExtJPG=.JPG
47set ExtGIF=.GIF
48set HDCopy=Y
49set HDKeep=Y
50set HDNewName=%
51set HDQuality=80
52set HDMaxW=0
53set HDMaxH=0
54set HDCvtOpt=
55set NormalQuality=80
56set NormalMaxW=0
57set NormalMaxH=350
58set NormalCvtOpt=
59set TNPrefix=TN-
60set TNQuality=80
61set TNMaxW=128
62set TNMaxH=128
63set TNCvtOpt=-rmeta
64
65rem ~ Read parameters
66set ParamFile=%~d0%~p0%~n0.Params.txt
67for /F "eol=; tokens=1,2* delims==" %%i in (%ParamFile%) do @set %%i=%%j
68
69rem ~ Loop on argv
70:loop_on_argv
71rem ~ parameter "~" remove """
72set argv1=%~1
73if not defined argv1 goto :not_argv1
74rem ~ Bad Arguments
75if not "%argv1:~0,1%" == "-" goto :usage
76set opt_name=%argv1:~1%
77shift /1
78rem ~ parameter "~" remove """
79set argv1=%~1
80rem ~ Bad Arguments
81if not defined argv1 goto :usage
82rem ~ Override parameters
83set opt_value=%argv1%
84shift /1
85set %opt_name%=%opt_value%
86goto :loop_on_argv
87:not_argv1
88
89rem ~ Override parameters - Read parfile
90if defined ParFile (for /F "eol=; tokens=1,2* delims==" %%i in (%ParFile%) do @set %%i=%%j)
91
92rem ~ if not Dirname and DirSrc and DirDest, done all directories
93if not defined DirName (
94  if not defined DirSrc (
95    if not defined DirDest goto :all_directories
96  )
97  rem ~ if DirSrc or DirDest not defined
98  rem ~ Bad Arguments
99  if not defined DirSrc goto :usage
100  if not defined DirDest goto :usage
101) else (
102  rem ~ if DirSrc defined
103  rem ~ Bad Arguments
104  if defined DirSrc goto :usage
105)
106
107
108rem ~ Define directory name
109rem ~ Expanded path contains short names only will defined after the directory was created
110if not defined DirSrc set DirSrc=%DirAlbum%\%DirName%
111if not defined DirDest set DirDest=%DirFTP%\%DirName%
112
113set DirPict=%DirDest%
114set DirHigh=%DirPict%\pwg_high
115set DirTN=%DirPict%\thumbnail
116
117rem ~ Directory name are convert to expanded path contains short names only
118rem ~ XnView don't like "dir name" with double quote
119for /F "tokens=*" %%i in ("%DirAlbum%") do set ExpandedDirAlbum=%%~si
120for /F "tokens=*" %%i in ("%DirFTP%") do set ExpandedDirFTP=%%~si
121
122echo.
123echo *** %DirSrc% ***
124
125rem ~ Check directory source
126if not exist "%DirSrc%" (
127echo.
128echo Error: Source directories don't exist
129echo.
130goto :usage
131)
132
133rem ~ Check directory Destination
134if not exist "%DirPict%" mkdir "%DirPict%"
135
136rem ~ Directory name are convert to expanded path contains short names only
137rem ~ XnView don't like "dir name" with double quote
138for /F "tokens=*" %%i in ("%DirSrc%") do set ExpandedDirSrc=%%~si
139for /F "tokens=*" %%i in ("%DirPict%") do set ExpandedDirPict=%%~si
140
141if /I "%ExpandedDirSrc%" == "%ExpandedDirPict%" (
142echo.
143echo Error: Source and destination directories cannot be same
144echo.
145goto :usage
146)
147
148if /I not %DelDestDir% == Y goto :end_DelDestDir
149echo.
150echo Deleting destination directories
151if exist "%DirPict%\*.*" del /Q /F /S "%DirPict%\*.*"
152if exist "%DirPict%" rmdir /Q /S "%DirPict%"
153:end_DelDestDir
154
155if /I not %HDCopy% == Y goto :convert_HD
156echo.
157echo Creating HD Pictures
158if exist "%DirSrc%\*%ExtJPG%" xcopy /F /R /I /H /C /Y "%DirSrc%\*%ExtJPG%" "%DirHigh%\*%ExtJPG%"
159if exist "%DirSrc%\*%ExtGIF%" xcopy /F /R /I /H /C /Y "%DirSrc%\*%ExtGIF%" "%DirHigh%\*%ExtGIF%"
160
161
162rem ~ -o filename       : Output filename
163rem ~ Use # to specify position of numeric enumerator
164rem ~ Use % to specify source filename
165rem ~ Use $ to specify source folder
166
167rem ~ -out format       : Output format name
168
169rem ~ -c value          : Compression number (default : 0)
170rem ~ -q value          : JPEG/PNG/FPX/WIC quality (default : 100)
171
172rem ~ -opthuff
173
174rem ~ -resize w h      : Scale width-height
175rem ~ w h can be percent (ex: -resize 100% 200%)
176
177rem ~ -i                : Interlaced GIF / Progressive JPEG
178
179:convert_HD
180echo.
181echo Convert HD Pictures
182if not exist "%DirHigh%" mkdir "%DirHigh%"
183rem ~ Directory name are convert to expanded path contains short names only
184rem ~ XnView don't like "dir name" with double quote
185for /F "tokens=*" %%i in ("%DirHigh%") do set ExpandedDirHigh=%%~si
186set HD_CVT_OPT=-q %HDQuality% %GlobalCvtOpt% %HDCvtOpt% -rtype linear -ratio -resize %HDMaxW% %HDMaxH%
187rem ~ Force Conversion for TIF
188if exist "%DirSrc%\*.TIF" "%DirXnView%\nconvert.exe" %HD_CVT_OPT% -out jpeg -o %ExpandedDirHigh%\%HDNewName%.WasTIF%ExtJPG% %ExpandedDirSrc%\*.TIF
189if %HDCopy% == Y goto :end_convert_HD
190if exist "%DirSrc%\*%ExtJPG%" "%DirXnView%\nconvert.exe" %HD_CVT_OPT% -out jpeg -o %ExpandedDirHigh%\%HDNewName%%ExtJPG% %ExpandedDirSrc%\*%ExtJPG%
191if exist "%DirSrc%\*%ExtGIF%" "%DirXnView%\nconvert.exe" %HD_CVT_OPT% -out gif -o %ExpandedDirHigh%\%HDNewName%%ExtGIF%  %ExpandedDirSrc%\*%ExtGIF%
192:end_convert_HD
193rem ~ Execute high addon
194if exist "%HDAddOnFile%" (
195echo Execute "%HDAddOnFile%"
196call "%HDAddOnFile%" %ExpandedDirHigh% HIGH
197)
198
199echo.
200echo Creating Normal Pictures
201set NO_CVT_OPT=-q %NormalQuality% %GlobalCvtOpt% %NormalCvtOpt% -rtype linear -ratio -resize %NormalMaxW% %NormalMaxH%
202if exist "%DirHigh%\*%ExtJPG%" "%DirXnView%\nconvert.exe" %NO_CVT_OPT% -out jpeg -o %ExpandedDirPict%\%%%ExtJPG% %ExpandedDirHigh%\*%ExtJPG%
203if exist "%DirHigh%\*%ExtGIF%" "%DirXnView%\nconvert.exe" %NO_CVT_OPT% -out gif  -o %ExpandedDirPict%\%%%ExtGIF% %ExpandedDirHigh%\*%ExtGIF%
204rem ~ Execute normal addon
205if exist "%NormalAddOnFile%" (
206echo Execute "%NormalAddOnFile%"
207call "%NormalAddOnFile%" %ExpandedDirPict% NORMAL
208)
209
210
211echo.
212echo Creating thumbnail Pictures
213if not exist "%DirTN%" mkdir "%DirTN%"
214rem ~ Directory name are convert to expanded path contains short names only
215rem ~ XnView don't like "dir name" with double quote
216for /F "tokens=*" %%i in ("%DirTN%") do set ExpandedDirTN=%%~si
217set TN_CVT_OPT=-q %TNQuality% %GlobalCvtOpt% %TNCvtOpt% -rtype linear -ratio -resize %TNMaxW% %TNMaxH%
218if exist "%DirHigh%\*%ExtJPG%" "%DirXnView%\nconvert.exe" %TN_CVT_OPT% -out jpeg -o %ExpandedDirTN%\%TNPrefix%%%%ExtJPG% %ExpandedDirHigh%\*%ExtJPG%
219if exist "%DirHigh%\*%ExtGIF%" "%DirXnView%\nconvert.exe" %TN_CVT_OPT% -out gif  -o %ExpandedDirTN%\%TNPrefix%%%%ExtGIF% %ExpandedDirHigh%\*%ExtGIF%
220rem ~ Execute thumbnail addon
221if exist "%TNAddOnFile%" (
222echo Execute "%TNAddOnFile%"
223call "%TNAddOnFile%" %ExpandedDirTN% THUMBNAIL
224)
225
226
227echo.
228echo Creating index.php
229if not exist "%DirAlbum%\index.php" goto :noindex
230xcopy /F /R /I /D /H /C /Y "%DirAlbum%\index.php" "%DirPict%\"
231xcopy /F /R /I /D /H /C /Y "%DirAlbum%\index.php" "%DirTN%\"
232xcopy /F /R /I /D /H /C /Y "%DirAlbum%\index.php" "%DirHigh%\"
233goto :end_index
234:noindex
235echo No file "%DirAlbum%\index.php" =^> no copies
236goto :end_index
237:end_index
238
239echo.
240echo Keeping or deleting HD directory
241if /I not %HDKeep% == N goto :keep_HD
242if exist "%DirHigh%\*.*" del /S /Q /F "%DirHigh%\*.*"
243if exist "%DirHigh%" rmdir /Q "%DirHigh%"
244:keep_HD
245
246goto :end
247
248:all_directories
249echo.
250echo *************************************************************
251echo * Apply %~n0 for all directories of %DirAlbum%
252echo *************************************************************
253echo.
254pause
255for /F "tokens=*" %%i in ('dir /B /A:D "%DirAlbum%"') do cmd /c %0 "%%i" %all_args%
256
257
258goto :end
259
260:usage
261echo Error Bad Parameter
262echo Syntax:
263echo   - All directories: %0 [-options] [-ParFile ^<File Name^>]
264echo   - Selected Directory: %0 ^<Short Directory Name^> [-DirDest ^<Full Directory Path^>] [-options] [-ParFile ^<File Name^>]
265echo   - Selected Directories src/dest: %0 -DirSrc ^<Full Directory Path^> -DirDest ^<Full Directory Path^> [-options] [-ParFile ^<File Name^>]
266echo.
267echo Key:
268echo   - ^<Short Directory Name^> : Directory on Album directory
269echo   - -DirSrc ^<Full Directory Path^> : Source directory
270echo     Override computed Album directory name
271echo     Cannot be used with ^<Short Directory Name^>
272echo   - -DirDest ^<Full Directory Path^> : Destination directory
273echo     Override computed FTP directory name
274echo   - [-options] can be composed of all parameters defined in %ParamFile%
275echo     Override parameters defined in %ParamFile%
276echo     Each option is composed with 2 line arguments -^<parameter name^> and ^<parameter value^>
277echo     Override before [-ParFile ^<File Name^>]
278echo   - [-ParFile ^<File Name^>] : Full name of parameters file
279echo     Override parameters defined in %ParamFile%
280echo     Override after [-options]
281echo.
282echo Examples:
283echo   %0
284echo   %0 -HDKeep N -TNQuality 70
285echo   %0 20050816
286echo   %0 20050816 -HDKeep N -TNQuality 70
287echo   %0 20050816 -DirDest c:\temp\FTP -HDKeep N -TNQuality 70
288echo   %0 -DirSrc c:\temp\test -DirDest c:\temp\testII -HDKeep N -TNQuality 70
289
290:end
Note: See TracBrowser for help on using the repository browser.