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