https://github.com/gibiee/img64
This library encodes and decodes an image in base64 format.
https://github.com/gibiee/img64
base64 base64-decoding base64-encoding image image-decoding image-encoding image-processing images
Last synced: 1 day ago
JSON representation
This library encodes and decodes an image in base64 format.
- Host: GitHub
- URL: https://github.com/gibiee/img64
- Owner: gibiee
- License: mit
- Created: 2023-11-30T10:56:21.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-06-05T08:23:05.000Z (10 months ago)
- Last Synced: 2025-12-15T07:38:32.061Z (4 months ago)
- Topics: base64, base64-decoding, base64-encoding, image, image-decoding, image-encoding, image-processing, images
- Language: Python
- Homepage: https://pypi.org/project/img64
- Size: 3.06 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README




This library encodes and decodes an image in base64 format.
# Installation
```sh
pip install img64
```
# Quick start
## Convert Image to Base64
```py
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
```py
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](https://github.com/ternaus/base64ToImageConverters).
- The referenced library doesn't ensure data consistency, but this library addresses that issue.
- This library enhances user convenience in handling both RGB and grayscale images.