Skip to content

Commit

Permalink
Optionally test image support with PIL
Browse files Browse the repository at this point in the history
  • Loading branch information
lukacu committed Jun 15, 2023
1 parent d0942d4 commit 3147619
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions support/tests/python/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import io
import numpy as np
from trax import MemoryImage, BufferImage
from PIL import Image

image1 = (np.random.random((100, 100, 3)) * 255).astype(np.uint8)

Expand All @@ -16,12 +15,21 @@

assert(np.array_equal(image2, timage2.array()))

try:
# Optional test if PIL is installed
from PIL import Image

image3 = Image.fromarray(image1)
bimage = io.BytesIO()
image3.save(bimage, format='JPEG')
simage = bimage.getvalue()

timage3 = BufferImage.create(simage)

assert(simage == timage3.buffer())

except ImportError:
print("PIL not installed, skipping file buffer test")

image3 = Image.fromarray(image1)
bimage = io.BytesIO()
image3.save(bimage, format='JPEG')
simage = bimage.getvalue()

timage3 = BufferImage.create(simage)

assert(simage == timage3.buffer())

0 comments on commit 3147619

Please sign in to comment.