Skip to content

gibiee/img64

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyPI - Version PyPI - Downloads PyPI - License PyPI - Python Version

This library converts images to base64 encoding and vice versa.

Installation

pip install img64

Quick start

Convert Image to Base64

from PIL import Image
import cv2
import img64

# PIL image to Base64
image = Image.open('sample.png')
base64 = img64.image_to_base64(image)
base64[:30] # 'iVBORw0KGgoAAAANSUhEUgAABAAAAA...'

# Numpy(OpenCV) image to Base64
image = cv2.imread('sample.png')
image = cv2.cvtColor(image, cv2.COLOR_BGRA2RGBA)
base64 = img64.image_to_base64(image)
base64[:30] # 'iVBORw0KGgoAAAANSUhEUgAABAAAAA...'

Convert Base64 to Image

import img64

# Base64 to PIL image
base64 = 'iVBORw0KGgoAAAANSUhEUgAABAAAAA...'
image = img64.base64_to_image(base64, type='pil')
type(image) # PIL.Image.Image

# Base64 to Numpy(OpenCV) image
base64 = 'iVBORw0KGgoAAAANSUhEUgAABAAAAA...'
image = img64.base64_to_image(base64, type='numpy')
type(image) # numpy.ndarray

Information

  • It was implemented by referencing ternaus/base64ToImageConverters.
    • The referenced library doesn't ensure data consistency, so this library addresses that issue.
    • This library enhances user convenience in handling both RGB and grayscale images.

About

This library converts images to base64 encoding and vice versa.

Topics

Resources

License

Stars

Watchers

Forks

Languages