@kitschpatrol/aphex 0.1.6 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitschpatrol/aphex",
3
- "version": "0.1.6",
3
+ "version": "0.2.0",
4
4
  "description": "Apple Photos Export. TypeScript library and CLI tool to export and process images and albums from your macOS Photos.app library.",
5
5
  "keywords": [
6
6
  "apple",
@@ -44,38 +44,39 @@
44
44
  "@sindresorhus/is": "^8.1.0",
45
45
  "defu": "^6.1.7",
46
46
  "execa": "^10.2.1",
47
- "exiftool-vendored": "^39.1.0",
48
- "fast-equals": "^6.2.1",
47
+ "exiftool-vendored": "^39.4.0",
48
+ "fast-equals": "^6.4.3",
49
49
  "fs-extra": "^11.4.1",
50
50
  "github-slugger": "^2.0.0",
51
- "image-size": "^2.0.4",
51
+ "image-size": "^2.3.0",
52
52
  "importx": "^0.5.2",
53
- "lognow": "^0.8.7",
53
+ "lognow": "^0.8.10",
54
54
  "mrmime": "^2.0.1",
55
55
  "piscina": "^5.3.2",
56
- "type-fest": "^5.10.0"
56
+ "type-fest": "^6.0.3"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@arethetypeswrong/core": "^0.18.5",
60
- "@clack/prompts": "^1.8.1",
61
- "@kitschpatrol/shared-config": "^8.14.0",
60
+ "@clack/prompts": "^1.9.0",
61
+ "@kitschpatrol/chagent": "^0.9.0",
62
+ "@kitschpatrol/shared-config": "^8.15.0",
62
63
  "@types/fs-extra": "^11.0.4",
63
64
  "@types/node": "~24.13.6",
64
- "@vitest/coverage-v8": "^5.0.5",
65
- "brewpub": "^0.5.0",
65
+ "@vitest/coverage-v8": "^5.1.2",
66
+ "brewpub": "^0.5.2",
66
67
  "bumpp": "^12.3.0",
67
68
  "globby": "^16.2.4",
68
- "markdown-table": "^3.0.4",
69
- "mdat-plugin-cli-help": "^3.4.1",
69
+ "markdown-table": "^3.1.0",
70
+ "mdat-plugin-cli-help": "^3.4.3",
70
71
  "open": "^11.0.4",
71
72
  "pretty-bytes": "^7.2.0",
72
73
  "pretty-ms": "^10.0.0",
73
74
  "publint": "^0.3.25",
74
75
  "shx": "^0.4.0",
75
- "tsdown": "^0.23.4",
76
+ "tsdown": "^0.23.7",
76
77
  "tsx": "^4.23.15",
77
78
  "typescript": "~6.0.3",
78
- "vitest": "^5.0.5"
79
+ "vitest": "^5.1.2"
79
80
  },
80
81
  "engines": {
81
82
  "node": "^24.16.0 || >=26.3.0"
@@ -97,7 +98,8 @@
97
98
  "clean-deep": "shx rm -f pnpm-lock.yaml && git clean -fdX",
98
99
  "fix": "pnpm build && ksc fix && mdat ./native/aphex-swift/readme.md",
99
100
  "lint": "pnpm build && ksc lint && mdat check ./native/aphex-swift/readme.md",
100
- "release": "bumpp --commit 'Release: %s' && pnpm build && pnpm publish --otp $(op item get npm --otp) && brewpub --tap kitschpatrol/tap",
101
+ "notarize": "./native/aphex-swift/notarize.sh",
102
+ "release": "bumpp --commit 'Release: %s' --all --execute 'chagent' && pnpm build && pnpm notarize && pnpm publish --otp $(op item get npm --otp) && brewpub --tap kitschpatrol/tap",
101
103
  "test": "vitest run",
102
104
  "test:coverage": "vitest run --coverage"
103
105
  }
package/readme.md CHANGED
@@ -38,7 +38,7 @@ It makes it simple to export high-quality versions of specific photos or albums
38
38
 
39
39
  I created this library for integration in static website content management asset pipelines, and to attempt to work around some issues related to [exporting high-quality versions of edited images](https://github.com/RhetTbull/osxphotos/discussions/1522) from the Photos.app library. (See the [unplugin-aphex](https://github.com/kitschpatrol/unplugin-aphex) project for an additional layer of integration with various build tools, and the [vscode-aphex-preview](https://github.com/kitschpatrol/vscode-aphex-preview) plugin for hover previews of Aphex links in VS Code.)
40
40
 
41
- This repository also embeds the `aphex-swift` CLI project, which provides a minimal and performant wrapper around parts of Apple's PhotoKit framework. It's not really intended for direct use beyond querying the Photos library and simple exports. It provides just enough functionality to support the parts of the methods provided by the `aphex` TypeScript library that can only be implemented natively.
41
+ This repository also embeds the `aphex-swift` CLI project, which provides a minimal and performant wrapper around parts of Apple's PhotoKit framework, and around the private frameworks Photos.app renders edited photos with. It's not really intended for direct use beyond querying the Photos library and exporting from it. It provides just enough functionality to support the parts of the methods provided by the `aphex` TypeScript library that can only be implemented natively.
42
42
 
43
43
  <!-- /* spell-checker:disable */ -->
44
44
 
@@ -84,11 +84,11 @@ brew install libavif mozjpeg imagemagick webp dssim ffmpeg guetzli oxipng
84
84
  | `webp` | WebP encoding (lossy, lossless, and near-lossless) |
85
85
  | `oxipng` | PNG optimization |
86
86
  | `guetzli` | High-quality JPEG recompression (used when size budgets require) |
87
- | `imagemagick` | General-purpose conversion and color profile handling |
87
+ | `imagemagick` | General-purpose conversion, color profile handling, transparency checks |
88
88
  | `ffmpeg` | Media probing used by some conversion paths |
89
89
  | `dssim` | Perceptual similarity metrics (only needed if `logSimilarity` is enabled) |
90
90
 
91
- If you skip image processing (`processOptions: 'disabled'`) you can omit these.
91
+ If you skip image processing (`processOptions: 'disabled'`) you can omit all of these but `imagemagick`, which is also used to check whether a photo has transparency when picking an export engine.
92
92
 
93
93
  #### CLI installation
94
94
 
@@ -146,9 +146,9 @@ It imagines the contents of your Photos.app library as a hierarchical file syste
146
146
 
147
147
  This lets you access specific photos in specific albums via a path-like syntax.
148
148
 
149
- Be warned that exporting unedited images is very fast, but exporting _edited_ images can be very (very) slow, since an alternate AppleScript-based export strategy is enabled by default to ensure maximum quality.
149
+ By default, different [export engines](#export-engines) are used for different types of images. The default configuration prioritizes image quality over export speed.
150
150
 
151
- By default, different export strategies are used for different types of images. The default configuration prioritizes image quality over export speed.
151
+ Edited photos get special treatment. The edited image that Photos.app keeps in its library is a fairly compressed JPEG or HEIC, and that file is all that PhotoKit will hand over. Photos.app itself does better when you choose File → Export, because it renders the edits again from the original image. By default, Aphex performs the same render through the private frameworks Photos.app uses, which gives the same pixels as the export sheet without touching the GUI.
152
152
 
153
153
  ### Library
154
154
 
@@ -180,13 +180,56 @@ The `options` parameter accepts a deeply partial `ExportOptions` object. All fie
180
180
 
181
181
  | Option group | Description |
182
182
  | ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
183
- | `exportOptions` | Controls which export engine is used per image type, file naming conventions (sluggify, UUID fragment, extension normalization), and AppleScript GUI export settings. |
183
+ | `exportOptions` | Controls which [export engine](#export-engines) is used per image type, file naming conventions (sluggify, UUID fragment, extension normalization), and the render settings of the `swift-render` and `photos-gui` engines. |
184
184
  | `processOptions` | Controls image processing: color profile normalization (`preserveColorProfiles`, `defaultColorProfile`), compression format and quality (`lossyFormat`, `lossyQuality`, `losslessFormat`), max dimensions and file size (`maxDimensionsPixels`, `maxFileSizeBytes`), and format passthrough (`passthroughFormats`). Set to `'disabled'` to skip processing. |
185
- | `metadataOptions` | Controls metadata written to exported images (creator, credit, description, label). Set to `'disabled'` to skip metadata management. |
186
- | `syncOptions` | Controls incremental export behavior: diff strategies (`diffStrategies`), whether to delete stale files (`deleteTarget`, `deleteOthers`), and force re-export (`forceUpdate`). Set to `'disabled'` to skip sync. |
185
+ | `metadataOptions` | Controls which XMP tags are copied from a photo's original file to the exported image (`tagsToSync`: creator, credit, description, label, preserved file name), and whether they are validated. Set to `'disabled'` to skip metadata management. |
186
+ | `syncOptions` | Controls incremental export behavior: diff strategies (`diffStrategies`), whether to delete stale files once the export has succeeded (`deleteTarget`, `deleteOthers`), and force re-export (`forceUpdate`). Set to `'disabled'` to skip sync. |
187
187
 
188
188
  See the [`ExportOptions` type](https://github.com/kitschpatrol/aphex/blob/main/src/index.ts) and the inline JSDoc on each field in [`src/pipeline/`](https://github.com/kitschpatrol/aphex/tree/main/src/pipeline) for the full set of options.
189
189
 
190
+ ##### Export engines
191
+
192
+ An engine is a way of getting an image file out of the Photos.app library. The `engineEdited`, `engineEditedAlpha`, `engineOriginal`, and `engineOriginalAlpha` export options each take either a single engine or a map from image format to engine.
193
+
194
+ | Engine | How it gets the file | Edited photos |
195
+ | ---------------- | ---------------------------------------------------------------------------------------------------- | ------------------------------- |
196
+ | `swift-render` | Renders the original image and its edits again with the private frameworks Photos.app uses. | Same as File → Export |
197
+ | `photos-gui` | Drives the Photos.app export sheet with AppleScript GUI automation. Slow, and takes over the screen. | Same as File → Export |
198
+ | `swift-photokit` | Asks PhotoKit for the image stored in the library. Fast, and originals come out untouched. | The compressed image in library |
199
+ | `file-system` | Copies the file straight out of the library folder. | The compressed image in library |
200
+ | `applescript` | Uses the `export` command of the Photos.app AppleScript dictionary. | A JPEG, format can't be chosen |
201
+
202
+ `swift-render` is the default for edited photos, and for original photos in lossless and raw formats. It writes JPEG, PNG, TIFF, or HEIC files, converts between color profiles, and scales images down, all configured through `exportOptions.swiftRenderOptions`:
203
+
204
+ ```ts
205
+ // A 16 bit Display P3 TIFF, straight from the render with no further processing
206
+ const result = await exportPhoto('Pets/Tiny', '~/Desktop', {
207
+ exportOptions: {
208
+ swiftRenderOptions: {
209
+ bitDepth: 16,
210
+ colorProfile: 'display-p3',
211
+ format: 'tiff',
212
+ },
213
+ },
214
+ processOptions: 'disabled',
215
+ })
216
+ ```
217
+
218
+ Some things to know about `swift-render`:
219
+
220
+ - It depends on private Photos APIs, so a macOS update can break it. It has been checked against Photos.app 10.0 on macOS 15.6 and Photos.app 12.0 on macOS 27.2. If a render fails for any reason, Aphex logs a warning and exports the photo through `photos-gui` instead, with export sheet settings that match `swiftRenderOptions`. The result is the same image, except that the export sheet can't keep transparency or use a background color, and has only four levels of JPEG quality and a single size limit. A photo that came out differently for one of those reasons is exported again on the next sync.
221
+ - Edits made with third-party editing extensions can't be rendered again, because only the extension understands its own edit data. For those photos the edited image stored in the library is converted instead, which is also what Photos.app does.
222
+ - With `includeMetadata` it writes the same title, caption, and keywords as Photos.app, but not the names of people identified in the photo. macOS doesn't let other apps read those from the library.
223
+
224
+ `swift-render` is also the only engine that can keep the transparency of an edited photo. Photos.app flattens transparent photos onto white, both in its export sheet and in the edited image it stores. Two options change that:
225
+
226
+ - `preserveAlpha`, which Aphex turns on by default, keeps the transparency in PNG and TIFF files.
227
+ - `background`, set to an sRGB color like `'ff8800'`, flattens the transparency onto that color instead of white, in any format.
228
+
229
+ Either way a transparent photo is rendered twice, once for its colors and once for its alpha channel, so it takes about three times as long. Unedited photos with transparency go through `swift-photokit` by default, since the original in the library is already intact.
230
+
231
+ The [`render-audit`](scripts/render-audit.ts) script exports an album through both `swift-render` and `photos-gui` and compares the results pixel by pixel.
232
+
190
233
  Functions are also provided for querying the contents of the Photos.app library:
191
234
 
192
235
  ##### `getPhotoInfo`
@@ -219,7 +262,7 @@ console.log(album.uuid, album.estimatedAssetCount)
219
262
 
220
263
  #### Logging
221
264
 
222
- Aphex logs progress and warnings via [lognow](https://github.com/kitschpatrol/lognow) for logging. You can inject your own logger:
265
+ Aphex logs progress and warnings via [lognow](https://github.com/kitschpatrol/lognow). You can inject your own logger:
223
266
 
224
267
  ```ts
225
268
  import { setLogger } from '@kitschpatrol/aphex'
@@ -236,10 +279,12 @@ Let's assume you have an album named "Trip" in your Photos.app library containin
236
279
  ```ts
237
280
  const result = await exportPhoto('Trip/IMG_1922.jpeg', '~/Desktop')
238
281
 
239
- // '/Users/$USER/Desktop/IMG_1922.jpeg'
282
+ // '/Users/$USER/Desktop/img_1922.png'
240
283
  console.log(result.path)
241
284
  ```
242
285
 
286
+ With the default options, the exported file gets a lowercase, URL-friendly name, and comes out as a PNG. Both can be changed, see `exportOptions.fileNameSluggify` and `processOptions`.
287
+
243
288
  Lookups are case-insensitive by default. Albums nested in folders are also supported, just add them to the identifier path:
244
289
 
245
290
  ```ts
@@ -253,7 +298,7 @@ Let's assume you have an album named "Pets" containing a photo you've titled "Ti
253
298
  ```ts
254
299
  const result = await exportPhoto('Pets/Tiny', '~/Desktop')
255
300
 
256
- // '/Users/$USER/Desktop/Tiny.jpeg'
301
+ // '/Users/$USER/Desktop/tiny.png'
257
302
  console.log(result.path)
258
303
  ```
259
304
 
@@ -267,7 +312,7 @@ const result = await exportPhoto('3AFE81DB-6BDB-42AB-AD27-90EE3A85A404', '~/Desk
267
312
 
268
313
  Note that UUIDs are unique to each instance of your Photos.app library, so if you have the same library synced across several machines, you can't expect the identifiers to be consistent. Technically, they aren't _universal_. Apple uses the term "local identifier" internally for this reason. For the sake of concision and consistency with tools like `osxphotos`, this library uses the term "UUID" interchangeably with "local identifier".
269
314
 
270
- #### Exporting an album by name
315
+ ##### Exporting an album by name
271
316
 
272
317
  Let's assume you have an album named "Pets" containing a number of photos. Export them all as follows:
273
318
 
@@ -275,11 +320,11 @@ Let's assume you have an album named "Pets" containing a number of photos. Expor
275
320
  const results = await exportPhotos(['Pets'], '~/Desktop')
276
321
  ```
277
322
 
278
- #### Exporting an album by UUID
323
+ ##### Exporting an album by UUID
279
324
 
280
325
  Like photos, albums also have local UUIDs in the Photos.app library.
281
326
 
282
- Let's assume you know the local UUID of the photo you want. (Maybe you looked it up using the `getAlbumInfo` function.)
327
+ Let's assume you know the local UUID of the album you want. (Maybe you looked it up using the `getAlbumInfo` function.)
283
328
 
284
329
  ```ts
285
330
  const results = await exportPhotos(['2768A20C-9BD0-42CB-B464-9D299952D389'], '~/Desktop')
@@ -287,7 +332,7 @@ const results = await exportPhotos(['2768A20C-9BD0-42CB-B464-9D299952D389'], '~/
287
332
 
288
333
  The same caveat about UUID consistency across library instances applies here.
289
334
 
290
- #### Exporting a mix of multiple photos and albums
335
+ ##### Exporting a mix of multiple photos and albums
291
336
 
292
337
  You can mix and match all the identifier forms as you like. Aphex will return a flat list of all the exported photos:
293
338
 
@@ -315,12 +360,20 @@ Aphex uses the bundled aphex-swift CLI tool to query the Photos.app library. The
315
360
 
316
361
  It's exposed as a binary as part of this package, so it's accessible on the command line via `aphex` within the scope of the `@kitschpatrol/aphex` package installation.
317
362
 
363
+ The `export` subcommand copies the image stored in the library by default. Pass `--format` to render the photo and its edits again at full quality instead, as described under [export engines](#export-engines):
364
+
365
+ ```sh
366
+ aphex export "Pets/Tiny" --destination ~/Desktop --format png --color-profile srgb
367
+ ```
368
+
318
369
  See the [project's readme](https://github.com/kitschpatrol/aphex/blob/main/native/aphex-swift/readme.md) for additional details.
319
370
 
320
371
  ## Implementation notes
321
372
 
322
373
  Currently, the TypeScript code bridges via simple CLI calls to the `aphex-swift` binary, which is a wrapper around parts of Apple's PhotoKit framework. This is flexible and fast enough for now, but projects like Kabir Oberai's [node-swift](https://github.com/kabiroberai/node-swift) could be a good alternative for tighter integration between native Swift code and the TypeScript API.
323
374
 
375
+ Rendering an edited photo follows what the Photos.app export sheet does internally. `aphex-swift` asks PhotoKit for the original image and the edit data, turns those into an edit "composition" with the private PhotosUIEdit framework, and renders it to a file with the private PhotoImaging framework. Everything private is looked up at runtime, so a macOS release that moves these pieces makes rendering fail with an error instead of breaking the whole tool. See [`PhotoRenderer.swift`](native/aphex-swift/Sources/PhotoRenderer.swift) for the details, and [`PhotoRendererAlpha.swift`](native/aphex-swift/Sources/PhotoRendererAlpha.swift) for how transparency is kept.
376
+
324
377
  Also, this library bundles a bunch of generically useful image processing functionality, which should probably live in a separate package.
325
378
 
326
379
  ## Resources
@@ -331,6 +384,26 @@ Also, this library bundles a bunch of generically useful image processing functi
331
384
 
332
385
  [kitschpatrol](https://github.com/kitschpatrol)
333
386
 
387
+ ### Building
388
+
389
+ `pnpm build` builds the TypeScript library and the `aphex-swift` binary, and signs the binary with the maintainer's Developer ID certificate. On a machine without that certificate, such as a test VM, sign ad hoc instead:
390
+
391
+ ```sh
392
+ APHEX_CODESIGN_IDENTITY=- pnpm build
393
+ ```
394
+
395
+ ### Releasing
396
+
397
+ `pnpm release` bumps the version, updates the changelog, builds and signs the `aphex-swift` binary, notarizes it with Apple, and then publishes to npm and Homebrew. The notarization step (`pnpm notarize`) reads its credentials from a Keychain profile named `notarytool`.
398
+
399
+ To save notarization credentials in that Keychain profile:
400
+
401
+ ```sh
402
+ xcrun notarytool store-credentials notarytool --apple-id <apple-id-email> --team-id <team-id>
403
+ ```
404
+
405
+ With the Apple ID and team ID supplied, `notarytool` prompts securely for the app-specific password.
406
+
334
407
  ## Acknowledgments
335
408
 
336
409
  Thank you to [Rhet Turnbull](https://github.com/RhetTbull) for creating [osxphotos](https://github.com/RhetTbull/osxphotos), which informed some of the export pipelines in this library.
@@ -343,9 +416,9 @@ Aphex borrows a technique from [Andreas Bentele](https://github.com/abentele)'s
343
416
 
344
417
  [Issues](https://github.com/kitschpatrol/aphex/issues) are welcome and appreciated.
345
418
 
346
- Please open an issue to discuss changes before submitting a pull request. Unsolicited PRs (especially AI-generated ones) are unlikely to be merged.
419
+ Please open an issue to discuss changes before submitting a pull request. Unsolicited PRs are unlikely to be merged.
347
420
 
348
- This repository uses [@kitschpatrol/shared-config](https://github.com/kitschpatrol/shared-config) (via its `ksc` CLI) for linting and formatting, plus [MDAT](https://github.com/kitschpatrol/mdat) for readme placeholder expansion.
421
+ This repository uses [ksc](https://github.com/kitschpatrol/shared-config) to handle linting and formatting with the usual tools, plus [mdat](https://github.com/kitschpatrol/mdat) for readme placeholder expansion, and [chagent](https://github.com/kitschpatrol/chagent) to maintain the [changelog](changelog.md).
349
422
 
350
423
  <!-- /contributing -->
351
424
 
@@ -353,9 +426,9 @@ This repository uses [@kitschpatrol/shared-config](https://github.com/kitschpatr
353
426
 
354
427
  This is an unofficial library and is not affiliated with or blessed by Apple Inc.
355
428
 
356
- The core export commands maintain a "read only" relationship with your library.
429
+ The `aphex` CLI only ever reads from your library. The TypeScript library does too, with one exception: with `metadataOptions.syncToEdited`, which is on by default, it copies XMP tags from a photo's original file onto the edited image file that Photos.app keeps for that photo inside the library. Set it to `false` for a strictly read-only export.
357
430
 
358
- None of the code paths should modify the contents of your Photos.app library. But regardless, strange things can happen — please back up your Photos.app library before using this tool.
431
+ Regardless, strange things can happen — please back up your Photos.app library before using this tool.
359
432
 
360
433
  This tool has _not_ been tested with iCloud-based Photos libraries.
361
434