1 @echo off & setlocal enableextensions enabledelayedexpansion
\r
2 :: ============================================================
\r
3 :: $Id: adjustimages.bat 15164 2009-01-22 22:22:30Z simonlarge $
\r
4 :: ============================================================
\r
5 :: This script verifies all .png images to see if they fit
\r
6 :: in the PDF version of the documentation. The FOP version we
\r
7 :: use doesn't scale images automatically when they are too
\r
9 :: We want images to be at most 5.75 inches wide and 9 inches
\r
11 :: The script retrieves the DPI setting in the image and
\r
12 :: and calculates the actual size of the image. If it exceeds
\r
13 :: the limits, the DPI setting of the image is increased to
\r
16 :: By default all images in all languages will be checked.
\r
17 :: You can specify a group of files to check using the first
\r
19 :: adjustimages en\Rev*.png
\r
21 :: The image manipulation is done using NConvert.exe from
\r
22 :: http://www.xnview.com
\r
23 :: ============================================================
\r
24 :: Set image size limits in 1000ths of an inch
\r
25 set /a w_limit = 5750
\r
26 set /a h_limit = 9000
\r
29 if '%1' == '' goto :DoDefault
\r
30 for %%? in (%1) do Call :ProcAdjustFile %%?
\r
34 for %%? in (de\*.png) do Call :ProcAdjustFile %%?
\r
35 for %%? in (en\*.png) do Call :ProcAdjustFile %%?
\r
36 for %%? in (es\*.png) do Call :ProcAdjustFile %%?
\r
37 for %%? in (fi\*.png) do Call :ProcAdjustFile %%?
\r
38 for %%? in (fr\*.png) do Call :ProcAdjustFile %%?
\r
39 for %%? in (id\*.png) do Call :ProcAdjustFile %%?
\r
40 for %%? in (ja\*.png) do Call :ProcAdjustFile %%?
\r
41 for %%? in (ru\*.png) do Call :ProcAdjustFile %%?
\r
43 for %%? in (f_info.txt) do if exist %%? del %%?
\r
44 endlocal & goto :EOF
\r
45 ::===============================================================
\r
46 :ProcAdjustFile FileName
\r
47 :: Extract resolution info from file
\r
48 setlocal enableextensions enabledelayedexpansion
\r
49 nconvert.exe -info %1>f_info.txt
\r
51 :: Extract image width, height and dpi
\r
52 :: Width = 3rd word on 10th line
\r
53 :: Height = 3rd word on 11th line
\r
54 :: XDPI = 3rd word on 19th line
\r
55 :: YDPI = 3rd word on 20th line
\r
56 :: Do the test. Get the third word of the tenth line.
\r
57 call :ProcGetLine f_info.txt 10 getLine
\r
58 for /f "tokens=3" %%? in ("%getLine%") do set /a w_image = %%?
\r
59 call :ProcGetLine f_info.txt 11 getLine
\r
60 for /f "tokens=3" %%? in ("%getLine%") do set /a h_image = %%?
\r
61 call :ProcGetLine f_info.txt 19 getLine
\r
62 for /f "tokens=3" %%? in ("%getLine%") do set /a xdpi = %%?
\r
63 call :ProcGetLine f_info.txt 20 getLine
\r
64 for /f "tokens=3" %%? in ("%getLine%") do set /a ydpi = %%?
\r
65 :: Set default dpi if no dpi was found
\r
66 set /a must_convert = 0
\r
69 set /a must_convert = 1
\r
73 set /a must_convert = 1
\r
76 :: Calculate image width and height (factor 1000 is used because
\r
77 :: of the integer math.
\r
78 set /a w_image_inch = w_image * 1000 / xdpi
\r
79 set /a h_image_inch = h_image * 1000 / ydpi
\r
80 rem echo Image (w - h): %w_image% - %h_image%
\r
81 rem echo DPI (x - y) : %xdpi% - %ydpi%
\r
82 rem echo Size (w - h) : %w_image_inch% - %h_image_inch%
\r
83 set /a w_delta = w_limit - w_image_inch
\r
84 set /a h_delta = h_limit - h_image_inch
\r
85 rem echo Delta (w - h): %w_delta% - %h_delta%
\r
86 :: If height and width are within limits, we're done
\r
87 :: If not, determine direction with largest overdraw and
\r
88 :: calculate a dpi setting that will fit the image into the
\r
90 :: Calculation method: new_dpi = (pixels * 1000) / limit
\r
91 if %w_delta% geq 0 (
\r
92 if %h_delta% geq 0 (
\r
93 if %must_convert% equ 1 (
\r
94 echo %1: image fits with default dpi
\r
97 echo %1: image is ok
\r
101 echo %1: image too high
\r
102 set /a new_dpi = h_image * 1000 / h_limit
\r
105 if %h_delta% geq 0 (
\r
106 echo %1: image too wide
\r
107 set /a new_dpi = w_image * 1000 / w_limit
\r
109 echo %1: image too wide and too high
\r
110 set /a new_xdpi = w_image * 1000 / w_limit
\r
111 set /a new_ydpi = h_image * 1000 / h_limit
\r
112 if !new_xdpi! leq !new_ydpi! (
\r
113 set /a new_dpi = !new_ydpi!
\r
115 set /a new_dpi = !new_xdpi!
\r
117 rem echo dpi required for width !new_xdpi!
\r
118 rem echo dpi required for height !new_ydpi!
\r
121 :: Make sure the dpi is large enough (integer arithmetic truncates)
\r
122 set /a new_dpi = new_dpi + 1
\r
123 echo adjust dpi to %new_dpi%
\r
124 nconvert.exe -dpi %new_dpi% %1 >nul
\r
126 endlocal & goto :EOF
\r
127 ::===============================================================
\r
128 :ProcGetLine FileName LineNro returnText
\r
129 setlocal enableextensions
\r
133 for /f "tokens=* skip=%lineNro_% delims=" %%r in ('type %1') do (
\r
134 if not defined return_ set return_=%%r)
\r
135 endlocal & set %3=%return_% & goto :EOF
\r