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 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 details)

Uploaded Source

Built Distribution

img64-1.0.0-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for img64-1.0.0.tar.gz
Algorithm Hash digest
SHA256 4702e56d6f60c9f190454c94227839aa6e4e6c268e7af3dc75b7b086933e0ae9
MD5 e58e524c8c54e6ff217953b587d9a310
BLAKE2b-256 f5e5f5620fd0620b9081cc135b4295ce351892bbc164a411c22b78e0d16c8539

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for img64-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cd8e80d519a672c5fb272e38a02ccc785f4a5b0a8b3a1bed1ffde5121b3f71d3
MD5 fdac19fe5e00da5127319f25261fdb50
BLAKE2b-256 94e7e04801611fbbc40ba6595f8838adcc9e8e39370c575513b879f2635ff05f

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