Skip to content

Commit

Permalink
Test opening many files
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Jan 9, 2022
1 parent eff6c34 commit 031dae4
Show file tree
Hide file tree
Showing 34 changed files with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions Tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import shutil
import sys
import tempfile
from pathlib import Path

import pytest

Expand Down Expand Up @@ -837,6 +838,59 @@ def test_fli_overrun2(self):
except OSError as e:
assert str(e) == "buffer overrun when reading image file"

def change_image_res(
self,
rep_image,
max_image_thresh=49,
percent_reduce_res=[0.1, 0.2, 0.3, 0.4, 0.5],
):

image_name = rep_image.name
save_all = True if rep_image.suffix == ".tiff" else False

with open(rep_image, "rb") as f:
image = Image.open(f)

if (image.size[0] * image.size[1]) / 1000000 > max_image_thresh:
for res in percent_reduce_res:
fixed_height = int(
int((float(image.size[1])))
- (res * int((float(image.size[1]))))
)
height_percent = fixed_height / float(image.size[1])
width_size = int((float(image.size[0]) * float(height_percent)))
if fixed_height * width_size / 1000000 < 50:
image = image.resize(
(width_size, fixed_height), Image.NEAREST
)
image.save(
image_name,
dpi=(300, 300),
save_all=save_all,
)
break
else:
image.save(
f"{image_name}", dpi=(300, 300), save_all=save_all
)

def test_open_files(self):
test_images = list(Path("./input_images").glob("*"))

count = 0
original = Image.MAX_IMAGE_PIXELS
Image.MAX_IMAGE_PIXELS = None
while True:
for i in test_images:
self.change_image_res(rep_image=i)
count += 1
print(count)
if count == 1400:
break
if count == 1400:
break
Image.MAX_IMAGE_PIXELS = original


class MockEncoder:
pass
Expand Down
Binary file added input_images/D001201640.tiff
Binary file not shown.
Binary file added input_images/D001201650.tiff
Binary file not shown.
Binary file added input_images/D001201660.tiff
Binary file not shown.
Binary file added input_images/D001201670.tiff
Binary file not shown.
Binary file added input_images/D001201680.tiff
Binary file not shown.
Binary file added input_images/D001201690.tiff
Binary file not shown.
Binary file added input_images/D001201700.tiff
Binary file not shown.
Binary file added input_images/D001201710.tiff
Binary file not shown.
Binary file added input_images/D001201720.tiff
Binary file not shown.
Binary file added input_images/D001201730.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added input_images/D001201731.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added input_images/D001201732.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added input_images/D001201733.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added input_images/D001201734.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added input_images/D001201735.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added input_images/D001201736.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added input_images/D001201737.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added input_images/D001201738.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added input_images/D001201739.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added input_images/D001201740.tiff
Binary file not shown.
Binary file added input_images/D001201750.tiff
Binary file not shown.
Binary file added input_images/D001201760.tiff
Binary file not shown.
Binary file added input_images/D001201770.tiff
Binary file not shown.
Binary file added input_images/D001201780.tiff
Binary file not shown.
Binary file added input_images/D001201790.tiff
Binary file not shown.
Binary file added input_images/D001201795.tiff
Binary file not shown.
Binary file added input_images/D001201800.tiff
Binary file not shown.
Binary file added input_images/D001201820.tiff
Binary file not shown.
Binary file added input_images/D001201830.tiff
Binary file not shown.
Binary file added input_images/D001201840.tiff
Binary file not shown.
Binary file added input_images/D001201850.tiff
Binary file not shown.
Binary file added input_images/D001201860.tiff
Binary file not shown.
Binary file added input_images/D001201870.tiff
Binary file not shown.

0 comments on commit 031dae4

Please sign in to comment.