Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Convert From HEIC to JPG in Python on WIndows

Im trying to convert HEIC to JPG using python. The only other answers about this topic used pyheif. I am on windows and pyheif doesn't support windows. Any suggestions? I am currently trying to use pillow.

like image 207
Stephan Yazvinski Avatar asked Sep 13 '20 00:09

Stephan Yazvinski


3 Answers

code below convert and save the picture as png format

from PIL import Image
import pillow_heif

    heif_file = pillow_heif.read_heif("HEIC_file.HEIC")
    image = Image.frombytes(
        heif_file.mode,
        heif_file.size,
        heif_file.data,
        "raw",
    
    )

    image.save("./picture_name.png", format("png"))
like image 91
adel Avatar answered Oct 13 '22 18:10

adel


As of today, I haven't found a way to do this with a Python-only solution. If you need a workaround, you can find any Windows command line utility that will do the conversion for you, and call that as a subprocess from Python.

Here is an example option using PowerShell: https://github.com/DavidAnson/ConvertTo-Jpeg

It's also pretty easy these days to write a .NET-based console app that uses Magick.NET. That's what I ended up doing.

like image 31
Jeff Avatar answered Oct 13 '22 16:10

Jeff


Just was looking at the same topic. I came across this:

https://pypi.org/project/heic-to-jpg/

I haven't had time to look more into this, but thought I'd share this.

like image 1
Volsie711 Avatar answered Oct 13 '22 16:10

Volsie711