I could easily convert HEIC to JPEG in python with a pyheic library. But the filesize gets larger when it's converted to JPEG. (About 4 times). Can I reduce the size of the file saving it?
How can I get base64-encoded string instead of saving JPEG image?
My code is as follows:
# -*- coding: utf-8 -*-
import sys
import os
from PIL import Image # pip3 install pillow
import pyheif # pip3 install pyheif
def call(oriPath, defPath):
try:
# if defPath is webp or heic
fileType = oriPath.split(".")[-1]
if fileType == "heic":
heif_file = pyheif.read(oriPath)
image = Image.frombytes(
heif_file.mode,
heif_file.size,
heif_file.data,
"raw",
heif_file.mode,
heif_file.stride,
)
image.save(defPath, "JPEG")
except:
print(False)
return
print(True)