I don't know what HEIC is. But for the time being, let's use PNG!

Preface

Do you sometimes get the message "This file format is not supported"? I was there. So I created a conversion program in python. I hope it helps someone.

environment

Library to use

code

from PIL import Image
import pyheif

heif_file = pyheif.read(image_path) # 1
data = Image.frombytes(             # 2
    heif_file.mode, 
    heif_file.size, 
    heif_file.data,
    "raw",
    heif_file.mode,
    heif_file.stride,
    )
image = data.resize(size)           # 3
image.save(save_path, "PNG")        # 4

What are you doing

  1. Read the HEIC image. At this time, "Heif File object" is created.
  2. Type them into the Image.frombytes module. At this time, an "Image object" is created.
  3. Then resize
  4. Complete with save

Finally

――It's easy, so if you have a lot of HEIC data, it's a good idea to make the above code a function and read it all at once with glob etc.!

reference

-Pyheif's github -Pillow Official

Recommended Posts

I don't know what HEIC is. But for the time being, let's use PNG!
Use logger with Python for the time being
I played with Floydhub for the time being
virtualenv For the time being, this is all!
What I got into Python for the first time
I will install Arch Linux for the time being.
I use python but I don't know the class well, so I will do a tutorial
What is the interface for ...
I want to move selenium for the time being [for mac]
I tried running PIFuHD on Windows for the time being
I didn't know how to use the [python] for statement
I want to create a Dockerfile for the time being.
I want to use the Ubuntu desktop environment on Android for the time being (Termux version)
I want to use Ubuntu's desktop environment on Android for the time being (UserLAnd version)
Understanding the python class Struggle (1) Let's move it for the time being
I made a function to check if the webhook is received in Lambda for the time being
Let's touch Google's Vision API from Python for the time being
For the time being, I want to convert files with ffmpeg !!
What is the python underscore (_) for?
I don't know the value error
I want to use Ubuntu's desktop environment on Android for the time being (Termux version-Japanese input in desktop environment)
For the time being using FastAPI, I want to display how to use API like that on swagger
I tried tensorflow for the first time
Python Master RTA for the time being
Let's try Linux for the first time
python I don't know how to get the printer name that I usually use.
I bought Sipeed Lichee Zero so I set it up for the time being
Let's display a simple template that is ideal for Django for the first time
I tried using scrapy for the first time
How to use MkDocs for the first time
For the time being, import them into jupyter
Make a histogram for the time being (matplotlib)
Run yolov4 "for the time being" on windows
I tried python programming for the first time.
Try using LINE Notify for the time being
I tried Mind Meld for the first time
I tried to scrape YouTube, but I can use the API, so don't do it.
I will try to summarize the links that seem to be useful for the time being
I tried Python on Mac for the first time.
Flow memo to move LOCUST for the time being
Run with CentOS7 + Apache2.4 + Python3.6 for the time being
Molecular dynamics simulation to try for the time being
I tried python on heroku for the first time
For the first time, I learned about Unix (Linux).
Let's start Python from Excel. I don't use VBA.
Next to Excel, for the time being, jupyter notebook
AI Gaming I tried it for the first time
I don't tweet, but I want to use tweepy: just display the search results on the console
Python3 I don't know the balanced binary search tree, but I wish I had a sorted set.
I was in charge of maintaining the Fabric script, but I don't know.> <To those who
What is a dog? Django--Getting Started with Form for the First Time POST Transmission Volume
I don't want to search for high para because it is IQ1 (how to use lightgbm_tuner)