capturegraph.adapters.dng_convert
#
Cross-Platform DNG Conversion#
Convert DNG (Digital Negative) raw files to PIL Images, JPEG, HEIF, and PNG. Tries Apple Core Image first (best quality on macOS), then falls back to rawpy with high-quality tone mapping settings.
Example
from capturegraph.adapters import dng_to_jpeg, dng_to_heif, dng_to_png, dng_to_pil
# Get as PIL Image for editing
pil_img = dng_to_pil("photo.dng")
pil_img.thumbnail((1024, 1024))
pil_img.save("thumb.jpg")
# Convert to JPEG (uses Apple on macOS, rawpy elsewhere)
dng_to_jpeg("photo.dng", "output.jpg")
# Convert to HEIF
dng_to_heif("photo.dng", "output.heic", quality=0.9)
# Convert to PNG (lossless)
dng_to_png("photo.dng", "output.png")
dng_to_pil(dng_path, max_axis=None)
#
Open a DNG file and return it as a PIL Image.
Uses Apple Core Image on macOS for best quality (native tone mapping), falls back to rawpy with high-quality AHD demosaicing elsewhere.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dng_path
|
str | Path
|
Path to the input DNG file. |
required |
max_axis
|
int
|
If provided, resize so the largest dimension equals this value. |
None
|
Returns:
| Type | Description |
|---|---|
Image
|
PIL.Image.Image: The processed image. |
Note
Remember to call .close() on the returned image when done.
Example
Source code in capturegraph-lib/capturegraph/adapters/dng_convert.py
dng_to_jpeg(dng_path, output_path, quality=1.0, max_axis=None)
#
Convert a DNG file to JPEG with high-quality tone mapping.
Uses Apple Core Image on macOS for best quality, falls back to rawpy with AHD demosaicing elsewhere.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dng_path
|
str | Path
|
Path to the input DNG file. |
required |
output_path
|
str | Path
|
Path for the output JPEG file. |
required |
quality
|
float
|
Compression quality (0.0-1.0). Default is 1.0 for max quality. |
1.0
|
max_axis
|
int
|
If provided, resize so the largest dimension equals this value. |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the created JPEG file. |
Example
Source code in capturegraph-lib/capturegraph/adapters/dng_convert.py
dng_to_heif(dng_path, output_path, quality=1.0, max_axis=None)
#
Convert a DNG file to HEIF with high-quality tone mapping.
Uses Apple Core Image on macOS for best quality, falls back to rawpy with AHD demosaicing elsewhere.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dng_path
|
str | Path
|
Path to the input DNG file. |
required |
output_path
|
str | Path
|
Path for the output HEIF file (.heic extension). |
required |
quality
|
float
|
Compression quality (0.0-1.0). Default is 1.0 for max quality. |
1.0
|
max_axis
|
int
|
If provided, resize so the largest dimension equals this value. |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the created HEIF file. |
Example
Source code in capturegraph-lib/capturegraph/adapters/dng_convert.py
dng_to_png(dng_path, output_path, max_axis=None)
#
Convert a DNG file to PNG (lossless) with high-quality tone mapping.
Uses Apple Core Image on macOS for best quality, falls back to rawpy with AHD demosaicing elsewhere.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dng_path
|
str | Path
|
Path to the input DNG file. |
required |
output_path
|
str | Path
|
Path for the output PNG file. |
required |
max_axis
|
int
|
If provided, resize so the largest dimension equals this value. |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the created PNG file. |