This library is a tool for converting images to base64 encoding and vice versa.
Project description
This library is a tool for converting images to base64 encoding and vice versa.
- It was implemented by referencing ternaus/base64ToImageConverters.
- The referenced code didn't ensure data consistency, so this code improves that issue.
- This code enhances user convenience in handling both RGB and grayscale images.
Installation
pip install img64
Quick start
Convert pil image to base64
from PIL import Image
import img64
image = Image.open('sample.png')
base64 = img64.image_to_base64(image)
base64[:30] # 'iVBORw0KGgoAAAANSUhEUgAABAAAAA...'
Convert numpy(opencv) image to base64
import cv2
import img64
image = cv2.imread('sample.png')
image = cv2.cvtColor(image, cv2.COLOR_BGRA2RGBA)
base64 = img64.image_to_base64(image)
base64[:30] # 'iVBORw0KGgoAAAANSUhEUgAABAAAAA...'
Convert base64 to pil image
import img64
base64 = 'iVBORw0KGgoAAAANSUhEUgAABAAAAA...'
image = img64.base64_to_image(base64, type='pil')
type(image) # PIL.Image.Image
Convert base64 to numpy image
import img64
base64 = 'iVBORw0KGgoAAAANSUhEUgAABAAAAA...'
image = img64.base64_to_image(base64, type='numpy')
type(image) # numpy.ndarray
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
img64-1.0.0.tar.gz
(3.3 kB
view hashes)
Built Distribution
img64-1.0.0-py3-none-any.whl
(3.4 kB
view hashes)