Created
October 2, 2017 21:16
-
-
Save gregchu/48c3d6deeb237cd569422b9907eded1f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from StringIO import StringIO | |
from PIL import Image | |
def encode_jpeg(img, quality=100): | |
"""Encode ndarray image into a jpeg | |
Args: | |
img: 3D (wxhxRGB) array | |
quality: jpeg compression quality | |
""" | |
s = StringIO() | |
img = Image.fromarray(img) | |
img.save(s, format="JPEG", quality=quality) | |
return s | |
def decode_jpeg(string_data): | |
"""Decode jpeg byte into to a Image object""" | |
return Image.open(string_data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment