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.
formatis"jpeg","png","heic", or"tiff". If you do not give it, Macotron uses the extension ofdest.qualityis a number from 0 to 1 for JPEG and HEIC. A higher value gives a better image and a larger file.maxSizeis the largest width or height in pixels. A larger image is scaled down and keeps its shape. A smaller image is not scaled up.
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
- macotron.fs to list and check files.
- The
heic-to-jpeg.jsplugin.