Skip to main content

This library is a tool for converting images to base64 encoding and vice versa.

Project description

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.

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.1.0.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

img64-1.1.0-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file img64-1.1.0.tar.gz.

File metadata

  • Download URL: img64-1.1.0.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.13

File hashes

Hashes for img64-1.1.0.tar.gz
Algorithm Hash digest
SHA256 b1e41a5f0b61e5407e2d335f951a9ca83e0f39979625e4c53ce20862a0104a90
MD5 417fa038ab4124c45186f1132000fe25
BLAKE2b-256 f80c82e02c9dcbdf9142d27e18ea58113fabdd9fa39590aa8c0cbb15a69cb35b

See more details on using hashes here.

File details

Details for the file img64-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: img64-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.13

File hashes

Hashes for img64-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0bb0caeeb7d12d9f652ef864eb2199c5fac5d2cf24dbf886d54975200ce091a0
MD5 7d60598ced4aab22b453818b477b38f2
BLAKE2b-256 69498460e39e242f2acecd89c33cbdd9fbddf714438b3dd9d36383061a9c5ff5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page