Macotron

macotron.image

Convert an image file to JPEG, PNG, HEIC, or TIFF. Macotron uses ImageIO, the same code that Preview uses, and keeps the photo's metadata.

// Convert one iPhone photo to a JPEG next to it.
const r = await macotron.image.convert("~/Downloads/IMG_0001.heic", "~/Downloads/IMG_0001.jpg", {
  format: "jpeg",
  quality: 0.9,
});
if (!r.ok) macotron.notify.toast("Convert failed", r.error, { color: "error" });

Converting

convert(src, dest, { format?, quality?, maxSize? }): Promise<{ ok, error? }>

Reads src and writes dest in the new format. Both paths expand ~. When dest exists, the call replaces it. When dest is the same file as src, the call fails and does not change the file.

The EXIF, GPS, and orientation tags go into the new file, so a photo stays the right way up.

When the source cannot be read or the destination cannot be written, ok is false and error tells why. The promise does not reject.

See also