Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- cls
- setlocal
- echo -------------------------------------------------------------------------------
- echo I Quickly create thumbnails for your Synology DiskStation I
- echo I I
- echo I created by Olaf Noehring, http://www.team-noehring.de I
- echo I version: 2012-09-17, v25a I
- echo -------------------------------------------------------------------------------
- echo.
- echo Edit/adjust the values in the Configuration area of this file only!
- echo.
- echo If you have special characters in your file-/pathnames (e.g. öäüß) the irfanview 4.33 version will stop working because it can not access the correct file/path! I have contacted Irfan (the irfanview programmer) about a special commandline parameter for this but have not received an answer.
- echo IMPORTANT:
- echo.
- echo EVEN FASTER:
- echo I suggest you set the source to your /photo (or a subdirectory), but the target to a local (on your PC) directory. This will read the image data only once from the network which (this script reads the thumbnails after the creation of the first thumbnail) should for the 2nd...5th thumbnail result in a VERY large speed increase: Files will be read and written from/to local directory = much faster. Afterwards simply transfer (copy) the created @eaDir to your DiskStation.
- echo You can start multiple instances - you MUST change the source (obviously).
- echo Each instance uses unique names for temporary files and a unique subdir in your target directory.
- echo Still: This will make more use of your network capacity in combination with CPU speed as your CPU and network will be more busy at all times.
- echo.
- echo PS: USE AT YOU OWN RISK!
- echo.
- pause
- :: --- Configuration START --->
- ::
- ::CHANGE THIS (1/3)
- ::
- :: Source folder - Where (probably a mapped drive) are your images (/photo directory)
- :: Make sure no special characters (öäüß etc.) are in your foldernames and filenames!
- ::Lets assume /photo is accessable from windows with driveletter z:
- ::NO trailing (back)slash!, NO quotes!
- set source=c:\TEMP\01_Fotos_bearbeiten
- ::
- ::CHANGE THIS TOO (2/3)
- ::
- :: Target folder - Where should the thumbnails (in @eaDir 's) be stored? They need to be transfered later using WinSCP for example to the appropiate folder of your DiskStation
- ::NO trailing (back)slash!, NO quotes!
- set target=c:\TEMP\02_Fotos_erledigt
- ::
- ::FINALLY ADJUST THIS (3/3)
- ::
- :: IrfanView application directory
- ::for my test I used irfanview version 4.33
- ::NO trailing (back)slash!, NO quotes!
- :: c:\Program Files (x86)\IrfanView\i_view32.exe
- :: set iview=c:\programme\irfanview\i_view32.exe
- set iview=c:\TEMP\IrfanView\i_view32.exe
- ::
- ::You CAN adjust the settings below - but you do NOT need to!
- ::
- ::Thumbnail sizes
- ::This should probably match the settings of your DiskStation
- set sizeXL=1280
- set sizeL=800
- set sizeB=640
- set sizeM=320
- set sizeS=120
- :: JPG compression Mode
- :: set jpgq=82
- :: JPG compression Mode
- set jpgqB=81
- :: JPG compression Mode
- set jpgqM=86
- :: JPG compression Mode
- set jpgqS=45
- :: JPG compression XL Bild
- set jpgqXL=93
- ::Extra quality? You can use "/resample" or just leave it empty!
- rem set extraquality=
- set extraquality=/resample
- :: <--- Configuration END ---
- ::
- :: DO NOT change below! (except you know what you are doing)
- ::
- ::Create uniquefilenames with a random number!
- ::%random% is a random number between 0 and 32768
- ::Number between 1 and 100:
- :: set /a randomNumber=%RANDOM% * 100 / 32768 + 1
- if (%1)==() (
- set /a randomNumber=%RANDOM%
- ) else (
- set /a randomNumber=%1
- )
- ::Make the user check the configuration
- echo Please check the settings that will be used:
- echo.
- echo - Source (subdirectories will also be treated):
- echo %source%
- echo - Target (unique so you can start this batch file multiple times)(subdirectories will be created):
- echo %target%\%randomNumber%
- echo - JPQ quality is (100 = very good ... 10 = very fast): %jpgq%
- echo - Extraquality is (NULL = quicker or /resample = better quality): %extraquality%
- echo - Sizes (long sides): %sizeXL%, %sizeL%, %sizeB%, %sizeM%, %sizeS%
- echo.
- echo The following is for information only and can not be changed by the user:
- echo - Unique (random) ID of this instance (prefix for filenames): %randomNumber%
- echo.
- echo If this is correct, please press any key. If this is wrong, stop this script with the keycombination CRTL-C (or STRG-C) right now!
- echo.
- pause
- ::Start measuring runtime after the user actually starts the complex process of indexing and converting/creating.
- ::Measure script time 1/2
- set start=%time%
- set startTotal=%start%
- ::Measure script time 1/2 END
- ::Run progress-meter script
- start cmd.exe /c "progress23x.cmd %randomNumber%"
- ::Generate a fileliste of all jpg files in /photo (your source drive)
- :: /S gives us all subdirectories (you might want to be careful as MANY files can result from this
- :: /B gives us filenames (with paths) only
- echo.
- echo -------------------------------------------------------------------------------
- set start=%time%
- echo Reading JPG files in %source% and it's subdirectories
- dir "%source%\*.jpg" /S /B >%randomNumber%_filelist_original.txt
- echo.|set /P ="..filelist created in: "
- call :OUTPUTTIME
- ::Count files and calulate how many thumbs will be created, inform the user
- echo.
- echo -------------------------------------------------------------------------------
- echo.|set /P ="Counting files... "
- set start=%time%
- set _File=%randomNumber%_filelist_original.txt
- set /a total_Lines=0
- for /f %%j in ('Type %_File%^|Find "" /v /c') do set /a total_Lines=%%j
- set /a total_massthumbs=total_Lines*5
- echo %total_massthumbs% thumbnails should be created (%total_Lines% files * 5 thumbs each)
- echo.|set /P ="..finished in: "
- call :OUTPUTTIME
- echo (If time-taken is 24+ hours, calculated result will be wrong. Same below.)
- echo Now let's start...
- ::Count end
- ::We use the filelist_original.txt to create a batch job for irfanview.
- echo.
- echo -------------------------------------------------------------------------------
- set start=%time%
- echo Creating XL version (%sizeXL% / something) thumbs (1 of 5)
- echo This step will take the longest time, each of the following will be quicker.
- echo Have patience - really! And ... I mean it! Really ... do not stop here - give it time!
- "%iview%" /filelist=%randomNumber%_filelist_original.txt /resize_long=%sizeXL% /aspectratio /convert="%target%\%randomNumber%\$D\@eaDir\$F\SYNOPHOTO_THUMB_XL.jpg" /filepattern="*.jpg" /jpgq=%jpgqXL% /silent /cmdexit %extraquality%
- echo.|set /P ="..finished in: "
- call :OUTPUTTIME
- ::for the smaller thumbs we search the TARGET (!) directory as we use only the 1280-thumbs to create the smaller (800-thumbs) now.
- ::This should save us a lot of calculation power and give us a noticeable speed improvement, especially if your original images have a 1280+ resolution.
- ::Of course this might result in (a little) quality loss - but the speed improvement should make this worth.
- ::the %3 in the filename (SYNOPHOTO_THUMB_XL) will be transformed on the DiskStation to a colon (:). We need the second % because the Windows commandline (DOS window) would assume this a special character.
- echo.
- :: echo -------------------------------------------------------------------------------
- :: set start=%time%
- :: echo Creating L version (%sizeL% / something) thumbs (2 of 5) ... please wait
- :: dir "%target%\%randomNumber%\SYNOPHOTO_THUMB_XL.*" /S /B >%randomNumber%_filelist_xl.txt
- ::Count files and calulate how many thumbs will be created, inform the user
- :: echo.|set /P =".counting XL thumbnails... "
- :: set _File=%randomNumber%_filelist_xl.txt
- :: set /a _LinesXL=0
- :: for /f %%j in ('Type %_File%^|Find "" /v /c') Do Set /a _LinesXL=%%j
- ::echo %_LinesXL% found (%total_Lines% expected)
- :: if (%_LinesXL%)==(%total_Lines%) (
- :: everything as expected, it seems no error occured
- :: echo.|set /P ="all %_LinesXL% found"
- :: ) else (
- :: echo.|set /P ="only %_LinesXL% found (%total_Lines% expected)"
- )
- ::Count end
- :: echo.|set /P ="..creating L size "
- :: "%iview%" /filelist=%randomNumber%_filelist_xl.txt /resize_long=%sizeL% /aspectratio /convert="$D\SYNOPHOTO_THUMB_L.jpg" /filepattern="*.jpg" /jpgq=%jpgqL% /silent /cmdexit %extraquality%
- :: echo.|set /P ="..finished in: "
- :: call :OUTPUTTIME
- ::for the smaller thumbs we search the TARGET (!) directory as we use only the 800-thumbs to create the smaller (640-thumbs) now.
- echo.
- echo -------------------------------------------------------------------------------
- set start=%time%
- echo Creating B version (%sizeB% / something) thumbs (3 of 5) ... please wait
- dir "%target%\%randomNumber%\SYNOPHOTO_THUMB_XL.*" /S /B >%randomNumber%_filelist_xl.txt
- ::Count files and calulate how many thumbs will be created, inform the user
- echo.|set /P =".counting L thumbnails... "
- set _File=%randomNumber%_filelist_xl.txt
- set /a _LinesL=0
- for /f %%j in ('Type %_File%^|Find "" /v /c') Do Set /a _LinesL=%%j
- ::echo %_LinesL% found (%total_Lines% expected)
- if (%_LinesL%)==(%total_Lines%) (
- :: everything as expected, it seems no error occured
- echo.|set /P ="all %_LinesL% found"
- ) else (
- echo.|set /P ="only %_LinesL% found (%total_Lines% expected)"
- )
- ::Count end
- echo.|set /P ="..creating B size "
- "%iview%" /filelist=%randomNumber%_filelist_xl.txt /resize_long=%sizeB% /aspectratio /convert="$D\SYNOPHOTO_THUMB_B.jpg" /filepattern="*.jpg" /jpgq=%jpgqB% /silent /cmdexit %extraquality%
- echo.|set /P ="..finished in: "
- call :OUTPUTTIME
- ::for the smaller thumbs we search the TARGET (!) directory as we use only the 640-thumbs to create the smaller (320-thumbs) now.
- echo.
- echo -------------------------------------------------------------------------------
- set start=%time%
- echo Creating M version (%sizeM% / something) thumbs (4 of 5) ... please wait
- dir "%target%\%randomNumber%\SYNOPHOTO_THUMB_B.*" /S /B >%randomNumber%_filelist_b.txt
- ::Count files and calulate how many thumbs will be created, inform the user
- echo.|set /P =".counting B thumbnails... "
- set _File=%randomNumber%_filelist_b.txt
- set /a _LinesB=0
- for /f %%j in ('Type %_File%^|Find "" /v /c') Do Set /a _LinesB=%%j
- ::echo %_LinesB% found (%total_Lines% expected)
- if (%_LinesB%)==(%total_Lines%) (
- :: everything as expected, it seems no error occured
- echo.|set /P ="all %_LinesB% found"
- ) else (
- echo.|set /P ="only %_LinesB% found (%total_Lines% expected)"
- )
- ::Count end
- echo.|set /P ="..creating M size "
- "%iview%" /filelist=%randomNumber%_filelist_b.txt /resize_long=%sizeM% /aspectratio /convert="$D\SYNOPHOTO_THUMB_M.jpg" /filepattern="*.jpg" /jpgq=%jpgqM% /silent /cmdexit %extraquality%
- echo.|set /P ="..finished in: "
- call :OUTPUTTIME
- ::for the smaller thumbs we search the TARGET (!) directory as we use only the 320-thumbs to create the smaller (120-thumbs) now.
- echo.
- echo -------------------------------------------------------------------------------
- set start=%time%
- echo Creating S version (%sizeS% / something) thumbs (5 of 5) ... please wait
- dir "%target%\%randomNumber%\SYNOPHOTO_THUMB_M.*" /S /B >%randomNumber%_filelist_m.txt
- ::Count files and calulate how many thumbs will be created, inform the user
- echo.|set /P =".counting M thumbnails... "
- set _File=%randomNumber%_filelist_m.txt
- set /a _LinesM=0
- for /f %%j in ('Type %_File%^|Find "" /v /c') Do Set /a _LinesM=%%j
- ::echo %_LinesM% M thumbnails found (%total_Lines% expected)
- if (%_LinesM%)==(%total_Lines%) (
- :: everything as expected, it seems no error occured
- echo.|set /P ="all %_LinesM% found"
- ) else (
- echo.|set /P ="only %_LinesM% found (%total_Lines% expected)"
- )
- ::Count end
- echo.|set /P ="..creating S size "
- "%iview%" /filelist=%randomNumber%_filelist_m.txt /resize_long=%sizeS% /aspectratio /convert="$D\SYNOPHOTO_THUMB_S.jpg" /filepattern="*.jpg" /jpgq=%jpgqS% /silent /cmdexit %extraquality%
- ::Finally count S thumbs
- dir "%target%\%randomNumber%\SYNOPHOTO_THUMB_S.*" /S /B >%randomNumber%_filelist_s.txt
- ::Count files and calulate how many thumbs will be created, inform the user
- echo.|set /P =".counting S thumbnails (final count)... "
- set _File=%randomNumber%_filelist_s.txt
- set /a _LinesS=0
- for /f %%j in ('Type %_File%^|Find "" /v /c') Do Set /a _LinesS=%%j
- ::echo %_LinesS% found (%total_Lines% expected)
- if (%_LinesS%)==(%total_Lines%) (
- :: everything as expected, it seems no error occured
- echo.|set /P ="all %_LinesS% found"
- ) else (
- echo.|set /P ="only %_LinesS% found (%total_Lines% expected)"
- )
- ::Count end
- echo.|set /P ="..finished in: "
- call :OUTPUTTIME
- ::Inform user about cleanup (remove temporary files
- echo.
- echo -------------------------------------------------------------------------------
- echo.|set /P ="Cleaning up (removing temporary files)... "
- ::echo .. deleting temporary filelist_original.txt
- del %randomNumber%_filelist_original.txt
- ::echo .. deleting temporary filelist_xl.txt
- del %randomNumber%_filelist_xl.txt
- ::echo .. deleting temporary filelist_l.txt
- del %randomNumber%_filelist_l.txt
- ::echo .. deleting temporary filelist_b.txt
- del %randomNumber%_filelist_b.txt
- ::echo .. deleting temporary filelist_m.txt
- del %randomNumber%_filelist_m.txt
- ::echo .. deleting temporary filelist_s.txt
- del %randomNumber%_filelist_s.txt
- ::Show Progress, END progress now - START
- del %randomNumber%_tmp_payload.flg
- ::Show Progress, END progress now - END
- echo done
- ::Output statistics
- set /a created_thumbs=_LinesXL+_LinesL+_LinesB+_LinesM+_LinesS
- echo.
- echo -------------------------------------------------------------------------------
- echo.
- echo Thumbnails of your %total_Lines% images in %source% (and it's subdirectories) should have been created (with quality: %jpgq%).
- echo Size : Count
- echo -----------------
- echo %sizeXL% : %_LinesXL%
- echo %sizeL% : %_LinesL%
- echo %sizeB% : %_LinesB%
- echo %sizeM% : %_LinesM%
- echo %sizeS% : %_LinesS%
- echo.
- echo Total : %created_thumbs%
- if (%created_thumbs%)==(%total_massthumbs%) (
- echo Everything seems all right
- ) else (
- echo Error?! Mismatch of expected and created thumbs!
- echo It should have been: %total_massthumbs%!
- echo One or more errors occured. Probably cause: Special characters exist in folder- and filenames! You may rename directories and files before, rename them back afterwards - this should avoid the error.
- )
- echo.
- echo Your results are in %target%\%randomNumber% (and it's subdirectories)
- echo.
- echo.|set /P ="Complete conversion took: "
- set start=%startTotal%
- call :OUTPUTTIME
- echo.
- echo.
- echo.
- echo.
- goto END
- :OUTPUTTIME
- ::Measure script time 2/2
- ::source: http://stackoverflow.com/questions/673523/how-to-measure-execution-time-of-command-in-windows-command-line
- set end=%time%
- set options="tokens=1-4 delims=:."
- for /f %options% %%a in ("%start%") do set start_h=%%a&set /a start_m=100%%b %% 100&set /a start_s=100%%c %% 100&set /a start_ms=100%%d %% 100
- for /f %options% %%a in ("%end%") do set end_h=%%a&set /a end_m=100%%b %% 100&set /a end_s=100%%c %% 100&set /a end_ms=100%%d %% 100
- set /a hours=%end_h%-%start_h%
- set /a mins=%end_m%-%start_m%
- set /a secs=%end_s%-%start_s%
- set /a ms=%end_ms%-%start_ms%
- if %hours% lss 0 set /a hours = 24%hours%
- if %mins% lss 0 set /a hours = %hours% - 1 & set /a mins = 60%mins%
- if %secs% lss 0 set /a mins = %mins% - 1 & set /a secs = 60%secs%
- if %ms% lss 0 set /a secs = %secs% - 1 & set /a ms = 100%ms%
- if 1%ms% lss 100 set ms=0%ms%
- :: mission accomplished
- set /a totalsecs = %hours%*3600 + %mins%*60 + %secs%
- echo %hours%:%mins%:%secs%.%ms% (%totalsecs%.%ms%s total)
- ::Measure script time 2/2 END
- goto :EOF
- :END
- endlocal
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement