@echo off rem ~ +-----------------------------------------------------------------------+ rem ~ | BuildPWGPicture - a Windows batch command for Piwigo | rem ~ | Copyright (C) 2007-2011 Ruben ARNAUD - rub@piwigo.org | rem ~ +-----------------------------------------------------------------------+ rem ~ | Version: 1.0.6.0 | rem ~ +-----------------------------------------------------------------------+ rem ~ | This program is free software; you can redistribute it and/or modify | rem ~ | it under the terms of the GNU General Public License as published by | rem ~ | the Free Software Foundation | rem ~ | | rem ~ | This program is distributed in the hope that it will be useful, but | rem ~ | WITHOUT ANY WARRANTY; without even the implied warranty of | rem ~ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | rem ~ | General Public License for more details. | rem ~ | | rem ~ | You should have received a copy of the GNU General Public License | rem ~ | along with this program; if not, write to the Free Software | rem ~ | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | rem ~ | USA. | rem ~ +-----------------------------------------------------------------------+ set DirName= rem ~ parameter "~" remove """ set argv1=%~1 if not defined argv1 goto :not_argv1_dirname if "%argv1:~0,1%" == "-" goto :not_argv1_dirname set DirName=%argv1% shift /1 :not_argv1_dirname rem ~ %* don't change with shift rem ~ on dos, there are only 9 max args set all_args=%1 %2 %3 %4 %5 %6 %7 %8 %9 rem ~ undefined parameters set DirSrc= set DirDest= set ParFile= rem ~ Default parameters set DirXnView=C:\Program Files\XnView set DirAlbum=F:\Album set DirFTP=C:\Docume~1\Ruben\Bureau\FTP set GlobalCvtOpt=-opthuff -i set ExtJPG=.JPG set ExtGIF=.GIF set HDCopy=Y set HDKeep=Y set HDNewName=% set HDQuality=80 set HDMaxW=0 set HDMaxH=0 set HDCvtOpt= set NormalQuality=80 set NormalMaxW=0 set NormalMaxH=350 set NormalCvtOpt= set TNPrefix=TN- set TNQuality=80 set TNMaxW=128 set TNMaxH=128 set TNCvtOpt=-rmeta rem ~ Read parameters set ParamFile=%~d0%~p0%~n0.Params.txt for /F "eol=; tokens=1,2* delims==" %%i in (%ParamFile%) do @set %%i=%%j rem ~ Loop on argv :loop_on_argv rem ~ parameter "~" remove """ set argv1=%~1 if not defined argv1 goto :not_argv1 rem ~ Bad Arguments if not "%argv1:~0,1%" == "-" goto :usage set opt_name=%argv1:~1% shift /1 rem ~ parameter "~" remove """ set argv1=%~1 rem ~ Bad Arguments if not defined argv1 goto :usage rem ~ Override parameters set opt_value=%argv1% shift /1 set %opt_name%=%opt_value% goto :loop_on_argv :not_argv1 rem ~ Override parameters - Read parfile if defined ParFile (for /F "eol=; tokens=1,2* delims==" %%i in (%ParFile%) do @set %%i=%%j) rem ~ if not Dirname and DirSrc and DirDest, done all directories if not defined DirName ( if not defined DirSrc ( if not defined DirDest goto :all_directories ) rem ~ if DirSrc or DirDest not defined rem ~ Bad Arguments if not defined DirSrc goto :usage if not defined DirDest goto :usage ) else ( rem ~ if DirSrc defined rem ~ Bad Arguments if defined DirSrc goto :usage ) rem ~ Define directory name rem ~ Expanded path contains short names only will defined after the directory was created if not defined DirSrc set DirSrc=%DirAlbum%\%DirName% if not defined DirDest set DirDest=%DirFTP%\%DirName% set DirPict=%DirDest% set DirHigh=%DirPict%\pwg_high set DirTN=%DirPict%\thumbnail rem ~ Directory name are convert to expanded path contains short names only rem ~ XnView don't like "dir name" with double quote for /F "tokens=*" %%i in ("%DirAlbum%") do set ExpandedDirAlbum=%%~si for /F "tokens=*" %%i in ("%DirFTP%") do set ExpandedDirFTP=%%~si echo. echo *** %DirSrc% *** rem ~ Check directory source if not exist "%DirSrc%" ( echo. echo Error: Source directories don't exist echo. goto :usage ) rem ~ Check directory Destination if not exist "%DirPict%" mkdir "%DirPict%" rem ~ Directory name are convert to expanded path contains short names only rem ~ XnView don't like "dir name" with double quote for /F "tokens=*" %%i in ("%DirSrc%") do set ExpandedDirSrc=%%~si for /F "tokens=*" %%i in ("%DirPict%") do set ExpandedDirPict=%%~si if /I "%ExpandedDirSrc%" == "%ExpandedDirPict%" ( echo. echo Error: Source and destination directories cannot be same echo. goto :usage ) if /I not %DelDestDir% == Y goto :end_DelDestDir echo. echo Deleting destination directories if exist "%DirPict%\*.*" del /Q /F /S "%DirPict%\*.*" if exist "%DirPict%" rmdir /Q /S "%DirPict%" :end_DelDestDir if /I not %HDCopy% == Y goto :convert_HD echo. echo Creating HD Pictures if exist "%DirSrc%\*%ExtJPG%" xcopy /F /R /I /H /C /Y "%DirSrc%\*%ExtJPG%" "%DirHigh%\*%ExtJPG%" if exist "%DirSrc%\*%ExtGIF%" xcopy /F /R /I /H /C /Y "%DirSrc%\*%ExtGIF%" "%DirHigh%\*%ExtGIF%" rem ~ -o filename : Output filename rem ~ Use # to specify position of numeric enumerator rem ~ Use % to specify source filename rem ~ Use $ to specify source folder rem ~ -out format : Output format name rem ~ -c value : Compression number (default : 0) rem ~ -q value : JPEG/PNG/FPX/WIC quality (default : 100) rem ~ -opthuff rem ~ -resize w h : Scale width-height rem ~ w h can be percent (ex: -resize 100% 200%) rem ~ -i : Interlaced GIF / Progressive JPEG :convert_HD echo. echo Convert HD Pictures if not exist "%DirHigh%" mkdir "%DirHigh%" rem ~ Directory name are convert to expanded path contains short names only rem ~ XnView don't like "dir name" with double quote for /F "tokens=*" %%i in ("%DirHigh%") do set ExpandedDirHigh=%%~si set HD_CVT_OPT=-q %HDQuality% %GlobalCvtOpt% %HDCvtOpt% -rtype linear -ratio -resize %HDMaxW% %HDMaxH% rem ~ Force Conversion for TIF if exist "%DirSrc%\*.TIF" "%DirXnView%\nconvert.exe" %HD_CVT_OPT% -out jpeg -o %ExpandedDirHigh%\%HDNewName%.WasTIF%ExtJPG% %ExpandedDirSrc%\*.TIF if %HDCopy% == Y goto :end_convert_HD if exist "%DirSrc%\*%ExtJPG%" "%DirXnView%\nconvert.exe" %HD_CVT_OPT% -out jpeg -o %ExpandedDirHigh%\%HDNewName%%ExtJPG% %ExpandedDirSrc%\*%ExtJPG% if exist "%DirSrc%\*%ExtGIF%" "%DirXnView%\nconvert.exe" %HD_CVT_OPT% -out gif -o %ExpandedDirHigh%\%HDNewName%%ExtGIF% %ExpandedDirSrc%\*%ExtGIF% :end_convert_HD rem ~ Execute high addon if exist "%HDAddOnFile%" ( echo Execute "%HDAddOnFile%" call "%HDAddOnFile%" %ExpandedDirHigh% HIGH ) echo. echo Creating Normal Pictures set NO_CVT_OPT=-q %NormalQuality% %GlobalCvtOpt% %NormalCvtOpt% -rtype linear -ratio -resize %NormalMaxW% %NormalMaxH% if exist "%DirHigh%\*%ExtJPG%" "%DirXnView%\nconvert.exe" %NO_CVT_OPT% -out jpeg -o %ExpandedDirPict%\%%%ExtJPG% %ExpandedDirHigh%\*%ExtJPG% if exist "%DirHigh%\*%ExtGIF%" "%DirXnView%\nconvert.exe" %NO_CVT_OPT% -out gif -o %ExpandedDirPict%\%%%ExtGIF% %ExpandedDirHigh%\*%ExtGIF% rem ~ Execute normal addon if exist "%NormalAddOnFile%" ( echo Execute "%NormalAddOnFile%" call "%NormalAddOnFile%" %ExpandedDirPict% NORMAL ) echo. echo Creating thumbnail Pictures if not exist "%DirTN%" mkdir "%DirTN%" rem ~ Directory name are convert to expanded path contains short names only rem ~ XnView don't like "dir name" with double quote for /F "tokens=*" %%i in ("%DirTN%") do set ExpandedDirTN=%%~si set TN_CVT_OPT=-q %TNQuality% %GlobalCvtOpt% %TNCvtOpt% -rtype linear -ratio -resize %TNMaxW% %TNMaxH% if exist "%DirHigh%\*%ExtJPG%" "%DirXnView%\nconvert.exe" %TN_CVT_OPT% -out jpeg -o %ExpandedDirTN%\%TNPrefix%%%%ExtJPG% %ExpandedDirHigh%\*%ExtJPG% if exist "%DirHigh%\*%ExtGIF%" "%DirXnView%\nconvert.exe" %TN_CVT_OPT% -out gif -o %ExpandedDirTN%\%TNPrefix%%%%ExtGIF% %ExpandedDirHigh%\*%ExtGIF% rem ~ Execute thumbnail addon if exist "%TNAddOnFile%" ( echo Execute "%TNAddOnFile%" call "%TNAddOnFile%" %ExpandedDirTN% THUMBNAIL ) echo. echo Creating index.php if not exist "%DirAlbum%\index.php" goto :noindex xcopy /F /R /I /D /H /C /Y "%DirAlbum%\index.php" "%DirPict%\" xcopy /F /R /I /D /H /C /Y "%DirAlbum%\index.php" "%DirTN%\" xcopy /F /R /I /D /H /C /Y "%DirAlbum%\index.php" "%DirHigh%\" goto :end_index :noindex echo No file "%DirAlbum%\index.php" =^> no copies goto :end_index :end_index echo. echo Keeping or deleting HD directory if /I not %HDKeep% == N goto :keep_HD if exist "%DirHigh%\*.*" del /S /Q /F "%DirHigh%\*.*" if exist "%DirHigh%" rmdir /Q "%DirHigh%" :keep_HD goto :end :all_directories echo. echo ************************************************************* echo * Apply %~n0 for all directories of %DirAlbum% echo ************************************************************* echo. pause for /F "tokens=*" %%i in ('dir /B /A:D "%DirAlbum%"') do cmd /c %0 "%%i" %all_args% goto :end :usage echo Error Bad Parameter echo Syntax: echo - All directories: %0 [-options] [-ParFile ^] echo - Selected Directory: %0 ^ [-DirDest ^] [-options] [-ParFile ^] echo - Selected Directories src/dest: %0 -DirSrc ^ -DirDest ^ [-options] [-ParFile ^] echo. echo Key: echo - ^ : Directory on Album directory echo - -DirSrc ^ : Source directory echo Override computed Album directory name echo Cannot be used with ^ echo - -DirDest ^ : Destination directory echo Override computed FTP directory name echo - [-options] can be composed of all parameters defined in %ParamFile% echo Override parameters defined in %ParamFile% echo Each option is composed with 2 line arguments -^ and ^ echo Override before [-ParFile ^] echo - [-ParFile ^] : Full name of parameters file echo Override parameters defined in %ParamFile% echo Override after [-options] echo. echo Examples: echo %0 echo %0 -HDKeep N -TNQuality 70 echo %0 20050816 echo %0 20050816 -HDKeep N -TNQuality 70 echo %0 20050816 -DirDest c:\temp\FTP -HDKeep N -TNQuality 70 echo %0 -DirSrc c:\temp\test -DirDest c:\temp\testII -HDKeep N -TNQuality 70 :end