@kitschpatrol/aphex 0.1.6 → 0.3.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.3.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.8",
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
 
@@ -74,21 +74,20 @@ npm install @kitschpatrol/aphex
74
74
  Full image processing functionality also requires a number of command-line tools available via [Homebrew](https://brew.sh):
75
75
 
76
76
  ```sh
77
- brew install libavif mozjpeg imagemagick webp dssim ffmpeg guetzli oxipng
77
+ brew install libavif mozjpeg imagemagick webp dssim ffmpeg oxipng
78
78
  ```
79
79
 
80
- | Tool | Used for |
81
- | ------------- | ------------------------------------------------------------------------- |
82
- | `libavif` | AVIF encoding |
83
- | `mozjpeg` | JPEG encoding |
84
- | `webp` | WebP encoding (lossy, lossless, and near-lossless) |
85
- | `oxipng` | PNG optimization |
86
- | `guetzli` | High-quality JPEG recompression (used when size budgets require) |
87
- | `imagemagick` | General-purpose conversion and color profile handling |
88
- | `ffmpeg` | Media probing used by some conversion paths |
89
- | `dssim` | Perceptual similarity metrics (only needed if `logSimilarity` is enabled) |
80
+ | Tool | Used for |
81
+ | ------------- | ----------------------------------------------------------------------------------------------- |
82
+ | `libavif` | AVIF encoding |
83
+ | `mozjpeg` | JPEG encoding, run from `$HOMEBREW_PREFIX/opt/mozjpeg` because Homebrew keeps it off the `PATH` |
84
+ | `webp` | WebP encoding (lossy, lossless, and near-lossless) |
85
+ | `oxipng` | PNG optimization |
86
+ | `imagemagick` | Transparency checks, and resizing to fit `maxDimensionsPixels` |
87
+ | `ffmpeg` | SSIM and PSNR similarity metrics (only needed if `logSimilarity` is enabled) |
88
+ | `dssim` | Perceptual similarity metrics (only needed if `logSimilarity` is enabled) |
90
89
 
91
- If you skip image processing (`processOptions: 'disabled'`) you can omit these.
90
+ 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
91
 
93
92
  #### CLI installation
94
93
 
@@ -146,9 +145,9 @@ It imagines the contents of your Photos.app library as a hierarchical file syste
146
145
 
147
146
  This lets you access specific photos in specific albums via a path-like syntax.
148
147
 
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.
148
+ By default, different [export engines](#export-engines) are used for different types of images. The default configuration prioritizes image quality over export speed.
150
149
 
151
- By default, different export strategies are used for different types of images. The default configuration prioritizes image quality over export speed.
150
+ 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
151
 
153
152
  ### Library
154
153
 
@@ -180,13 +179,56 @@ The `options` parameter accepts a deeply partial `ExportOptions` object. All fie
180
179
 
181
180
  | Option group | Description |
182
181
  | ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
183
- | `exportOptions` | Controls which export engine is used per image type, file naming conventions (sluggify, UUID fragment, extension normalization), and AppleScript GUI export settings. |
182
+ | `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
183
  | `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. |
184
+ | `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. |
185
+ | `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
186
 
188
187
  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
188
 
189
+ ##### Export engines
190
+
191
+ 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.
192
+
193
+ | Engine | How it gets the file | Edited photos |
194
+ | ---------------- | ---------------------------------------------------------------------------------------------------- | ------------------------------- |
195
+ | `swift-render` | Renders the original image and its edits again with the private frameworks Photos.app uses. | Same as File → Export |
196
+ | `photos-gui` | Drives the Photos.app export sheet with AppleScript GUI automation. Slow, and takes over the screen. | Same as File → Export |
197
+ | `swift-photokit` | Asks PhotoKit for the image stored in the library. Fast, and originals come out untouched. | The compressed image in library |
198
+ | `file-system` | Copies the file straight out of the library folder. | The compressed image in library |
199
+ | `applescript` | Uses the `export` command of the Photos.app AppleScript dictionary. | A JPEG, format can't be chosen |
200
+
201
+ `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`:
202
+
203
+ ```ts
204
+ // A 16 bit Display P3 TIFF, straight from the render with no further processing
205
+ const result = await exportPhoto('Pets/Tiny', '~/Desktop', {
206
+ exportOptions: {
207
+ swiftRenderOptions: {
208
+ bitDepth: 16,
209
+ colorProfile: 'display-p3',
210
+ format: 'tiff',
211
+ },
212
+ },
213
+ processOptions: 'disabled',
214
+ })
215
+ ```
216
+
217
+ Some things to know about `swift-render`:
218
+
219
+ - 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, the export fails with an error that names the photo. Aphex doesn't switch to another engine on its own. To export such a photo anyway, choose a different engine for it, such as `swift-photokit` for the image stored in the library.
220
+ - 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.
221
+ - 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.
222
+
223
+ `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:
224
+
225
+ - `preserveAlpha`, which Aphex turns on by default, keeps the transparency in PNG and TIFF files.
226
+ - `background`, set to an sRGB color like `'ff8800'`, flattens the transparency onto that color instead of white, in any format.
227
+
228
+ 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.
229
+
230
+ 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.
231
+
190
232
  Functions are also provided for querying the contents of the Photos.app library:
191
233
 
192
234
  ##### `getPhotoInfo`
@@ -219,7 +261,7 @@ console.log(album.uuid, album.estimatedAssetCount)
219
261
 
220
262
  #### Logging
221
263
 
222
- Aphex logs progress and warnings via [lognow](https://github.com/kitschpatrol/lognow) for logging. You can inject your own logger:
264
+ Aphex logs progress and warnings via [lognow](https://github.com/kitschpatrol/lognow). You can inject your own logger:
223
265
 
224
266
  ```ts
225
267
  import { setLogger } from '@kitschpatrol/aphex'
@@ -236,10 +278,12 @@ Let's assume you have an album named "Trip" in your Photos.app library containin
236
278
  ```ts
237
279
  const result = await exportPhoto('Trip/IMG_1922.jpeg', '~/Desktop')
238
280
 
239
- // '/Users/$USER/Desktop/IMG_1922.jpeg'
281
+ // '/Users/$USER/Desktop/img_1922.png'
240
282
  console.log(result.path)
241
283
  ```
242
284
 
285
+ 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`.
286
+
243
287
  Lookups are case-insensitive by default. Albums nested in folders are also supported, just add them to the identifier path:
244
288
 
245
289
  ```ts
@@ -253,7 +297,7 @@ Let's assume you have an album named "Pets" containing a photo you've titled "Ti
253
297
  ```ts
254
298
  const result = await exportPhoto('Pets/Tiny', '~/Desktop')
255
299
 
256
- // '/Users/$USER/Desktop/Tiny.jpeg'
300
+ // '/Users/$USER/Desktop/tiny.png'
257
301
  console.log(result.path)
258
302
  ```
259
303
 
@@ -267,7 +311,7 @@ const result = await exportPhoto('3AFE81DB-6BDB-42AB-AD27-90EE3A85A404', '~/Desk
267
311
 
268
312
  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
313
 
270
- #### Exporting an album by name
314
+ ##### Exporting an album by name
271
315
 
272
316
  Let's assume you have an album named "Pets" containing a number of photos. Export them all as follows:
273
317
 
@@ -275,11 +319,11 @@ Let's assume you have an album named "Pets" containing a number of photos. Expor
275
319
  const results = await exportPhotos(['Pets'], '~/Desktop')
276
320
  ```
277
321
 
278
- #### Exporting an album by UUID
322
+ ##### Exporting an album by UUID
279
323
 
280
324
  Like photos, albums also have local UUIDs in the Photos.app library.
281
325
 
282
- Let's assume you know the local UUID of the photo you want. (Maybe you looked it up using the `getAlbumInfo` function.)
326
+ Let's assume you know the local UUID of the album you want. (Maybe you looked it up using the `getAlbumInfo` function.)
283
327
 
284
328
  ```ts
285
329
  const results = await exportPhotos(['2768A20C-9BD0-42CB-B464-9D299952D389'], '~/Desktop')
@@ -287,7 +331,7 @@ const results = await exportPhotos(['2768A20C-9BD0-42CB-B464-9D299952D389'], '~/
287
331
 
288
332
  The same caveat about UUID consistency across library instances applies here.
289
333
 
290
- #### Exporting a mix of multiple photos and albums
334
+ ##### Exporting a mix of multiple photos and albums
291
335
 
292
336
  You can mix and match all the identifier forms as you like. Aphex will return a flat list of all the exported photos:
293
337
 
@@ -315,12 +359,20 @@ Aphex uses the bundled aphex-swift CLI tool to query the Photos.app library. The
315
359
 
316
360
  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
361
 
362
+ 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):
363
+
364
+ ```sh
365
+ aphex export "Pets/Tiny" --destination ~/Desktop --format png --color-profile srgb
366
+ ```
367
+
318
368
  See the [project's readme](https://github.com/kitschpatrol/aphex/blob/main/native/aphex-swift/readme.md) for additional details.
319
369
 
320
370
  ## Implementation notes
321
371
 
322
372
  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
373
 
374
+ 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.
375
+
324
376
  Also, this library bundles a bunch of generically useful image processing functionality, which should probably live in a separate package.
325
377
 
326
378
  ## Resources
@@ -331,6 +383,26 @@ Also, this library bundles a bunch of generically useful image processing functi
331
383
 
332
384
  [kitschpatrol](https://github.com/kitschpatrol)
333
385
 
386
+ ### Building
387
+
388
+ `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:
389
+
390
+ ```sh
391
+ APHEX_CODESIGN_IDENTITY=- pnpm build
392
+ ```
393
+
394
+ ### Releasing
395
+
396
+ `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`.
397
+
398
+ To save notarization credentials in that Keychain profile:
399
+
400
+ ```sh
401
+ xcrun notarytool store-credentials notarytool --apple-id <apple-id-email> --team-id <team-id>
402
+ ```
403
+
404
+ With the Apple ID and team ID supplied, `notarytool` prompts securely for the app-specific password.
405
+
334
406
  ## Acknowledgments
335
407
 
336
408
  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 +415,9 @@ Aphex borrows a technique from [Andreas Bentele](https://github.com/abentele)'s
343
415
 
344
416
  [Issues](https://github.com/kitschpatrol/aphex/issues) are welcome and appreciated.
345
417
 
346
- Please open an issue to discuss changes before submitting a pull request. Unsolicited PRs (especially AI-generated ones) are unlikely to be merged.
418
+ Please open an issue to discuss changes before submitting a pull request. Unsolicited PRs are unlikely to be merged.
347
419
 
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.
420
+ 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, [chagent](https://github.com/kitschpatrol/chagent) to maintain the [changelog](changelog.md), and [brewpub](https://github.com/kitschpatrol/brewpub) to publish the Homebrew formula.
349
421
 
350
422
  <!-- /contributing -->
351
423
 
@@ -353,9 +425,9 @@ This repository uses [@kitschpatrol/shared-config](https://github.com/kitschpatr
353
425
 
354
426
  This is an unofficial library and is not affiliated with or blessed by Apple Inc.
355
427
 
356
- The core export commands maintain a "read only" relationship with your library.
428
+ 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
429
 
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.
430
+ Regardless, strange things can happen — please back up your Photos.app library before using this tool.
359
431
 
360
432
  This tool has _not_ been tested with iCloud-based Photos libraries.
361
433