User:Riviera/Crop

From XPUB & Lens-Based wiki
< User:Riviera
Revision as of 20:11, 24 February 2024 by Riviera (talk | contribs) (adjusted transclusion tags)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

CROP Ratios On Paper

These notes are concerned with a bash script I wrote recently, applied to ConTeXt and then translated to Python. The output of the script is a list of dimensions corresponding to a particular ratio. I would like it to extend it to a pdf-output. Interaction with the command line interface could be like this: crop --ratio=2:3 --paper-size=A4 portrait.pdf

First two empty lists are declared

x = []
y = []

Subsequently, the variables of paper_height and paper_width are given.

paper_height = 297
paper_width = 210

The code could be improved by allowing the user to provide an argument. For example --papersize=A4, whereupon the dimensions of the A-series paper size could be retrieved from somewhere for use in the calculations. I’ll think about implementing this feature at a later point. Next up are two variables, step_x and step_y.

step_x = 3
step_y = 2

Let’s fill the list with some values

for n in range(step_x, paper_height, step_x):
    x += [n]

for n in range(step_y, paper_width, step_y):
    y += [n]

The lists, though of different lengths, are now full of numbers. These amount to two sequences of numbers within a particular range. When aligned, the relationship between the numbers in the lists are always in proportion to the ratio given by the user. Here is how the lists can be aligned:

i = 0
for n in range(0, len(x)):
    print(y[i], x[i])
    i += 1
2 3
4 6
6 9
8 12
10 15
12 18
14 21
16 24
18 27
20 30
22 33
24 36
26 39
28 42
30 45
32 48
34 51
36 54
38 57
40 60
42 63
44 66
46 69
48 72
50 75
52 78
54 81
56 84
58 87
60 90
62 93
64 96
66 99
68 102
70 105
72 108
74 111
76 114
78 117
80 120
82 123
84 126
86 129
88 132
90 135
92 138
94 141
96 144
98 147
100 150
102 153
104 156
106 159
108 162
110 165
112 168
114 171
116 174
118 177
120 180
122 183
124 186
126 189
128 192
130 195
132 198
134 201
136 204
138 207
140 210
142 213
144 216
146 219
148 222
150 225
152 228
154 231
156 234
158 237
160 240
162 243
164 246
166 249
168 252
170 255
172 258
174 261
176 264
178 267
180 270
182 273
184 276
186 279
188 282
190 285
192 288
194 291
196 294

Sample output might look like this in PDF format. The typesetting area in the image below is based on Van de Graaf's canon; the left margin is 1/9th of the page width and the right margin is 2/9ths. Likewise, the header is 1/9th of the page height and the footer is 2/9ths. The lists of dimensions could be useful for creating custom page sizes that fit on standard page sizes. The code would benefit from the implementation of an integer which divides the page into sections to determine typesetting space. In general, this could be useful for creating template page layouts for ConTeXt documents.

Ratios.pdf