Skip to content
This repository has been archived by the owner on Feb 13, 2019. It is now read-only.

Commit

Permalink
Fix for some weird image with a broken quant table
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Sinchok committed May 29, 2014
1 parent 21154da commit 9a93d04
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 26 deletions.
23 changes: 16 additions & 7 deletions betty/cropper/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,25 @@ def optimize_image(image_id):
image.optimized.name = optimized_upload_to(image, filename)
if format == "JPEG":
# For JPEG files, we need to make sure that we keep the quantization profile
im.save(
image.optimized.name,
icc_profile=icc_profile,
quality="keep",
subsampling=subsampling
)
try:
im.save(
image.optimized.name,
icc_profile=icc_profile,
quality="keep",
subsampling=subsampling
)
except TypeError as e:
# Maybe the image already had an invalid quant table?
if e.message.startswith("Not a valid numbers of quantization tables"):
im.save(
image.optimized.name,
icc_profile=icc_profile
)
else:
raise
else:
im.save(image.optimized.name, icc_profile=icc_profile)
image.save()
print(image.optimized)

return image_id

Expand Down
19 changes: 0 additions & 19 deletions tests/test_image_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,22 +155,3 @@ def test_gif_upload(self):

def tearDown(self):
shutil.rmtree(settings.BETTY_IMAGE_ROOT, ignore_errors=True)

# def test_large_image_upload(self):
# assert self.client.login(username="admin", password=self.password)
# image_path = os.path.join(TEST_DATA_PATH, 'huge.jpg')
# with open(image_path, "rb") as huge:
# data = {"image": huge, "name": "A COOL TRAIN"}
# res = self.client.post('/images/api/new', data)
# self.assertEqual(res.status_code, 200)
# response_json = json.loads(res.content.decode("utf-8"))
# self.assertEqual(response_json.get('name'), 'A COOL TRAIN')

# image = Image.objects.get(id=response_json['id'])
# self.assertTrue(os.path.exists(image.path()))
# self.assertTrue(os.path.exists(image.optimized.path))
# img = PILImage.open(image.optimized.path)
# self.assertEqual(img.size[0], settings.BETTY_MAX_WIDTH)

# self.assertEqual(os.path.basename(image.source.path), "huge.jpg")
# self.assertEqual(image.name, "A COOL TRAIN")

0 comments on commit 9a93d04

Please sign in to comment.