apyhub
Cover illustration for How to Convert HEIC to JPG or PNG Programmatically (cURL and Python)
Tutorials

How to Convert HEIC to JPG or PNG Programmatically (cURL and Python)

How to Convert HEIC to JPG or PNG Programmatically (cURL and Python)

01Introduction

To convert HEIC to JPG in your app, send the HEIC file to the HEIC to JPG API and save the JPG it returns. The same API returns a PNG when you name the output file .png.

Here is the whole thing in one request:

· bash
curl -X POST "https://api.eu.apyhub.com/apyhub/convert-heic-heif-to-jpeg-or-png/multi-part/download" \
  -H "apy-token: $APY_TOKEN" \
  -F "image=@IMG_0042.heic" \
  -o IMG_0042.jpg

That call uploads IMG_0042.heic and writes the converted JPG to disk. The rest of this guide covers why HEIC needs converting at all, how to get PNG instead of JPG, the URL-based endpoints, and a working Python example.

02Why HEIC files need converting

HEIC is Apple's container for photos stored in the High Efficiency Image File Format (HEIF). Apple added HEIF support in iOS 11 and macOS High Sierra and recommends it as the capture format on iPhone, according to Apple Support's guide to HEIF and HEVC media. Apple also notes that photos shared by AirDrop, Messages, or email "might" be converted to JPEG automatically. Files uploaded through a web form or synced from cloud storage often arrive as the original HEIC.

Browser support is the real problem. As of September 2026, Can I use lists HEIF/HEIC as supported only in Safari 17 and later. Chrome, Firefox, and Edge do not render it, which covers most of your users. If someone uploads an iPhone photo to your app and you display it as-is, most visitors see a broken image.

So the practical fix is to convert HEIC to a format every browser and tool reads:

  • JPG for photos. Smaller files, universal support, the right default for profile pictures, listings, and galleries.
  • PNG for lossless output. Larger files, useful when an image goes into a design tool or another processing step and you want to avoid a second round of JPG compression.

03How the HEIC to JPG API works

The HEIC to JPG API has four POST endpoints. Pick one based on where your image is and what you want back.

EndpointSendGet back
/multi-part/downloadThe HEIC file as image (multipart, up to 100 MB)The converted image as binary
/multi-part/linkThe HEIC file as image (multipart, up to 100 MB)JSON with a signed URL in data
/url/downloadJSON body with a public urlThe converted image as binary
/url/linkJSON body with a public urlJSON with a signed URL in data

All four share one optional query parameter, output, which sets the filename of the result.

Choosing JPG or PNG

Output is JPG by default. To get a PNG, end the output filename in .png:

· bash
curl -X POST "https://api.eu.apyhub.com/apyhub/convert-heic-heif-to-jpeg-or-png/url/link?output=photo.png" \
  -H "apy-token: $APY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"url":"https://assets.apyhub.com/samples/sample.heic"}'

The response is a JSON object with a signed link to the PNG:

· json
{
  "data": "https://apyhub-outgoing.s3.eu-west-1.amazonaws.com/mono-go/image-processor/.../heic-png_2026-10-07_c08d9486.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Expires=900&...&response-content-type=image%2Fpng&X-Amz-Signature=..."
}

Leave output out, or end it in .jpg, and the same request returns a JPG with response-content-type=image/jpeg. Signed links expire after 15 minutes (X-Amz-Expires=900), so download the file or copy it to your own storage before then.

04Convert HEIC to JPG in Python

This example takes a HEIC file from disk and saves the JPG next to it.

· python
import os
import requests

API_URL = "https://api.eu.apyhub.com/apyhub/convert-heic-heif-to-jpeg-or-png/multi-part/download"

def heic_to_jpg(path: str) -> str:
    out_path = os.path.splitext(path)[0] + ".jpg"
    with open(path, "rb") as f:
        resp = requests.post(
            API_URL,
            headers={"apy-token": os.environ["APY_TOKEN"]},
            files={"image": (os.path.basename(path), f, "image/heic")},
            params={"output": os.path.basename(out_path)},
            timeout=60,
        )
    resp.raise_for_status()
    with open(out_path, "wb") as out:
        out.write(resp.content)
    return out_path

print(heic_to_jpg("IMG_0042.heic"))

For PNG, change the extension in out_path to .png. The output parameter picks it up.

05Where this fits in an upload pipeline

A common pattern for apps that accept photos from phones:

  1. Accept the upload. Check the file extension or MIME type for .heic, .heif, image/heic, or image/heif.
  2. Send HEIC files to the HEIC to JPG API. Pass JPG and PNG uploads straight through.
  3. Shrink the result with the Image Compression API, since iPhone photos are large even after conversion.
  4. Optionally serve a WebP version with the JPEG to WebP API, or bundle images into a document with the Image to PDF API.

The API handles one image per request. For a folder of photos, loop over the files and send one request each.

Try the HEIC to JPG API in your browser

06Using it from AI agents with ApyHub MCP

Every endpoint in the ApyHub catalog, including the HEIC to JPG API, is available through ApyHub MCP. AI agents and coding assistants such as Claude can discover the converter, check its inputs, and call it directly, with no hand-written wrapper or tool definition. When you ask an assistant to "add HEIC support to the upload form," it can wire in a ready-made catalog endpoint instead of writing and debugging its own image-decoding code. You get consistent results and spend fewer tokens.

07Conclusion

HEIC is the photo format iPhones are set up to use, and most browsers still can't display it. Converting on the server is the reliable fix. With the HEIC to JPG API, that is one HTTP request: upload the file or send its URL, choose JPG or PNG with the output filename, and get a file or a signed link back. The cURL and Python examples above work as-is.

Start converting HEIC files free, no card required

08FAQ

What is a HEIC file?

HEIC is the file extension Apple uses for photos stored in the High Efficiency Image File Format (HEIF). iPhones have supported it since iOS 11, and Apple recommends it as the capture format because it keeps quality high at smaller file sizes.

How do I convert HEIC to JPG programmatically?

Send a POST request with the HEIC file to the HEIC to JPG API. Use /multi-part/download to upload a file and get the JPG back as binary, or /url/link to send a public URL and get a signed link. JPG is the default output.

How do I get PNG instead of JPG?

Set the output query parameter to a filename ending in .png, for example ?output=photo.png. Without it, or with a .jpg name, the API returns a JPG.

Does the API convert HEIF files too?

Yes. HEIC and HEIF use the same underlying format, and the API accepts both.

Can I convert many HEIC files at once?

Each request converts one image. To convert a batch, send one request per file. The examples above are easy to wrap in a loop.

What is the maximum file size?

Multipart uploads accept up to 100 MB per request. That covers any single iPhone photo with a lot of room to spare.

How long does the signed link last?

Links from the /link endpoints expire after 15 minutes. Download the image or copy it to your own storage if you need it longer.

Which programming languages can I use?

Any language that can make an HTTP request. This guide shows cURL and Python. The same calls work from JavaScript, PHP, Go, Java, Ruby, or a no-code tool.

How can I test the API before writing code?

Open the HEIC to JPG API page and use the built-in playground to send a real request and see the result. You can also run the cURL examples above from a terminal, or save them as requests in Voiden, an offline-first API client that stores requests as Markdown files in your repo.

Can I try it for free?

Yes. ApyHub has a free tier with no card required. See pricing for plan details.

09About ApyHub

ApyHub is a curated API catalog and the trusted operational layer between your application and the services it depends on. One subscription, billed in atoms, covers the whole catalog of over 1,500 endpoints and capabilities, and it keeps growing. Every service is evaluated before it is listed and carries machine-readable certification covering GDPR, SOC 2, and ISO 27001 alignment. Every endpoint is MCP-ready by default, so AI agents can call it directly. ApyHub runs in dedicated EU and US regions and serves more than 65,000 developer workspaces every month. You can start on the free tier with no card. If you build APIs, you can publish them on ApyHub and reach those developers.