Skip to main content

images/README.md

1# images
3These scripts are for working with images and other visual material.
5## The individual scripts
7<!-- [[[cog
9# This adds the root of the repo to the PATH, which has cog_helpers.py
10from os.path import abspath, dirname
11import sys
13sys.path.append(abspath(dirname(dirname("."))))
15import cog_helpers
17folder_name = "images"
19scripts = [
20 {
21 "usage": "chunky_pixels.py [PATH] [PIXEL_SIZE]",
22 "description": """
23 redraw an image using “chunky” pixels – that is, replacing every NxN block of pixels with a single colour.
24 <p>
25 <table>
26 <tr>
27 <td>
28 <img src="examples/flowers.jpg">
29 original
30 </td>
31 <td>
32 <img src="examples/flowers_12.jpg">
33 N=12
34 </td>
35 <td>
36 <img src="examples/flowers_34.jpg">
37 N=34
38 </td>
39 <td>
40 <img src="examples/flowers_68.jpg">
41 N=68
42 </td>
43 <td>
44 <img src="examples/flowers_204.jpg">
45 N=204
46 </td>
47 </tr>
48 </table>
49 </p>
50 """,
51 },
52 {
53 "usage": "convert_gif_to_mp4 GIF_PATH",
54 "description": "convert an animated GIF to an MP4 file"
55 },
56 {
57 "name": "copycrop.py",
58 "description": """
59 this script will “copy” the crop from one image pair to another.
60 <p>For example, suppose I have a full-screen screenshot and a crop to a small region of the screen:</p>
61 <p>
62 <table>
63 <tr>
64 <td><img src="examples/light_original.png"></td>
65 <td>&amp;</td>
66 <td><img src="examples/light_crop.png"></td>
67 </tr>
68 </table>
69 </p>
70 I can use this tool to extract the equivalent region from a second screenshot:
71 <p>
72 <table>
73 <tr>
74 <td><img src="examples/dark_original.png"></td>
75 <td>&rarr;</td>
76 <td><img src="examples/dark_crop.png"></td>
77 </tr>
78 </table>
79 </p>
80 I often use this when making images for my website, to create identical light mode and dark mode screenshots.
81 """
82 },
83 {
84 "usage": "images_only_pdf.py [PATH]",
85 "description": """
86 take a PDF, and create a new PDF which just has the images filling the page.
87 I use this to work around an odd behaviour of the “Scan Document” feature in Notes.app, where it adds a large white border around scanned images that I don’t want.
88 <p><strong>Note:</strong> this script overwrites the original file.</p>
89 """
90 },
91 {
92 "usage": "pdfthumb.py [PATH] --page=[PAGE]",
93 "description": """
94 get a PNG thumbnail of a specific page of a PDF, for example <code>pdfthumb pattern.pdf --page=3</code> will create a thumbnail of the third page.
95 """
96 },
97 {
98 "usage": "reborder.py [PATH] [BORDER_WIDTH]",
99 "description": """
100 replace empty space around an image with consistent white padding.
101 I use this when cleaning up screenshots, to get equal padding around the entire image.
102 <p>
103 <table>
104 <tr>
105 <td><img src="examples/reborder_original.png"></td>
106 <td>&rarr;</td>
107 <td><img src="examples/reborder_50.png"></td>
108 </tr>
109 </table>
110 </p>
111 """
112 },
113 {
114 "usage": "squarify.py [PATH]",
115 "description": """
116 crop an image to a central square
117 """
118 },
119 {
120 "usage": "srgbify.py [PATH]",
121 "description": """
122 convert an image in-place to have an sRGB colour profile.
123 """
124 },
125 {
126 "usage": "tint_image.py [PATH] [HEX_COLOUR]",
127 "description": """
128 take a greyscale image, and create a version which is tinted with the specified colour.
129 This works by creating an RGBA image which has the specified colour on every pixel, but controlling the intensity with the alpha value.
130 <p>
131 <table>
132 <tr>
133 <td><img src="examples/grayscale_circle.png"></td>
134 <td>&rarr;</td>
135 <td><img src="examples/grayscale_circle.ff0000.png"></td>
136 </tr>
137 </table>
138 </p>
139 I don’t use this script very often, but I checked it in because I thought it was a neat trick I didn’t want to forget.
140 """
141 },
144cog_helpers.create_description_table(folder_name=folder_name, scripts=scripts)
146]]]-->
147<dl>
148 <dt>
149 <a href="https://github.com/alexwlchan/scripts/blob/main/images/chunky_pixels.py">
150 <code>chunky_pixels.py [PATH] [PIXEL_SIZE]</code>
151 </a>
152 </dt>
153 <dd>
154 redraw an image using “chunky” pixels – that is, replacing every NxN block of pixels with a single colour.
155 <p>
156 <table>
157 <tr>
158 <td>
159 <img src="examples/flowers.jpg">
160 original
161 </td>
162 <td>
163 <img src="examples/flowers_12.jpg">
164 N=12
165 </td>
166 <td>
167 <img src="examples/flowers_34.jpg">
168 N=34
169 </td>
170 <td>
171 <img src="examples/flowers_68.jpg">
172 N=68
173 </td>
174 <td>
175 <img src="examples/flowers_204.jpg">
176 N=204
177 </td>
178 </tr>
179 </table>
180 </p>
181 </dd>
183 <dt>
184 <a href="https://github.com/alexwlchan/scripts/blob/main/images/convert_gif_to_mp4">
185 <code>convert_gif_to_mp4 GIF_PATH</code>
186 </a>
187 </dt>
188 <dd>
189 convert an animated GIF to an MP4 file
190 </dd>
192 <dt>
193 <a href="https://github.com/alexwlchan/scripts/blob/main/images/copycrop.py">
194 <code>copycrop.py</code>
195 </a>
196 </dt>
197 <dd>
198 this script will “copy” the crop from one image pair to another.
199 <p>For example, suppose I have a full-screen screenshot and a crop to a small region of the screen:</p>
200 <p>
201 <table>
202 <tr>
203 <td><img src="examples/light_original.png"></td>
204 <td>&amp;</td>
205 <td><img src="examples/light_crop.png"></td>
206 </tr>
207 </table>
208 </p>
209 I can use this tool to extract the equivalent region from a second screenshot:
210 <p>
211 <table>
212 <tr>
213 <td><img src="examples/dark_original.png"></td>
214 <td>&rarr;</td>
215 <td><img src="examples/dark_crop.png"></td>
216 </tr>
217 </table>
218 </p>
219 I often use this when making images for my website, to create identical light mode and dark mode screenshots.
220 </dd>
222 <dt>
223 <a href="https://github.com/alexwlchan/scripts/blob/main/images/images_only_pdf.py">
224 <code>images_only_pdf.py [PATH]</code>
225 </a>
226 </dt>
227 <dd>
228 take a PDF, and create a new PDF which just has the images filling the page.
229 I use this to work around an odd behaviour of the “Scan Document” feature in Notes.app, where it adds a large white border around scanned images that I don’t want.
230 <p><strong>Note:</strong> this script overwrites the original file.</p>
231 </dd>
233 <dt>
234 <a href="https://github.com/alexwlchan/scripts/blob/main/images/pdfthumb.py">
235 <code>pdfthumb.py [PATH] --page=[PAGE]</code>
236 </a>
237 </dt>
238 <dd>
239 get a PNG thumbnail of a specific page of a PDF, for example <code>pdfthumb pattern.pdf --page=3</code> will create a thumbnail of the third page.
240 </dd>
242 <dt>
243 <a href="https://github.com/alexwlchan/scripts/blob/main/images/reborder.py">
244 <code>reborder.py [PATH] [BORDER_WIDTH]</code>
245 </a>
246 </dt>
247 <dd>
248 replace empty space around an image with consistent white padding.
249 I use this when cleaning up screenshots, to get equal padding around the entire image.
250 <p>
251 <table>
252 <tr>
253 <td><img src="examples/reborder_original.png"></td>
254 <td>&rarr;</td>
255 <td><img src="examples/reborder_50.png"></td>
256 </tr>
257 </table>
258 </p>
259 </dd>
261 <dt>
262 <a href="https://github.com/alexwlchan/scripts/blob/main/images/squarify.py">
263 <code>squarify.py [PATH]</code>
264 </a>
265 </dt>
266 <dd>
267 crop an image to a central square
268 </dd>
270 <dt>
271 <a href="https://github.com/alexwlchan/scripts/blob/main/images/srgbify.py">
272 <code>srgbify.py [PATH]</code>
273 </a>
274 </dt>
275 <dd>
276 convert an image in-place to have an sRGB colour profile.
277 </dd>
279 <dt>
280 <a href="https://github.com/alexwlchan/scripts/blob/main/images/tint_image.py">
281 <code>tint_image.py [PATH] [HEX_COLOUR]</code>
282 </a>
283 </dt>
284 <dd>
285 take a greyscale image, and create a version which is tinted with the specified colour.
286 This works by creating an RGBA image which has the specified colour on every pixel, but controlling the intensity with the alpha value.
287 <p>
288 <table>
289 <tr>
290 <td><img src="examples/grayscale_circle.png"></td>
291 <td>&rarr;</td>
292 <td><img src="examples/grayscale_circle.ff0000.png"></td>
293 </tr>
294 </table>
295 </p>
296 I don’t use this script very often, but I checked it in because I thought it was a neat trick I didn’t want to forget.
297 </dd>
298</dl>
299<!-- [[[end]]] (sum: 9yBrlmL4gH) -->