Today, I will show how to convert HEIC file into PNG in python.
HEIC file is High Efficiency Image File Format. It is for storing individual images and image sequences.
But HEIC format file does not accept my image editors or blog. So today I want to show how to convert HEIC file into PNG in Python.
Convert HEIC into PNG in Python
Firstly, you need to install python library "pillow_heif".
Additionall, I also use Pillow library to save heic format data into png format.
Also, I provide you sample heic file to test your script. You can see more free heic files here.
The sample source code is below.
from PIL import Image
import pillow_heif
image_file = "sample1.heic"
im = pillow_heif.read_heif(image_file)
image = Image.frombytes(
mode = im.mode,
size = im.size,
data = im.data
)
image.save("convert_png.png", format("png"))
As you can see save format, you can also save HEIC file into JPEG, TIFF and others. It is always up to you and your project.
Reference
● bigcat88 (no date) Bigcat88/PILLOW_HEIF: Python library to work with HEIF files and an add-on for pillow., GitHub. Available at: https://github.com/bigcat88/pillow_heif (Accessed: January 8, 2023).
● Sample heic files download (no date) Sample HEIC Files Download - Get Examples Instantly. Available at: https://filesamples.com/formats/heic (Accessed: January 8, 2023).
If you have any question, please write a comment!
'software Engineering > python' 카테고리의 다른 글
How to convert m4a file into mp3 file in Python (0) | 2023.01.10 |
---|