def test_image_transcoding_bypass(space_resource, format): """ Test that JPEGs and PNGs bypass transcoding """ data = get_test_image_data(format=format) ri = ResourceImage(resource=space_resource, sort_order=8, type="main", image=ContentFile(data, name="nice.%s" % format)) ri.full_clean() assert ri.image_format == format # Transcoding did not occur assert Image.open(ri.image).format == format # no, no transcoding ri.image.seek(0) # PIL may have `seek`ed or read the stream assert ri.image.read() == data # the bitstream is identical
def test_image_transcoding(space_resource, format, image_type): """ Test that images get transcoded into JPEG or PNG if they're not JPEG/PNG """ data = get_test_image_data(format=format) ri = ResourceImage(resource=space_resource, sort_order=8, type=image_type, image=ContentFile(data, name="long_horse.%s" % format)) expected_format = ("PNG" if image_type in ("map", "ground_plan") else "JPEG") ri.full_clean() assert ri.image_format == expected_format # Transcoding occurred assert Image.open(ri.image).format == expected_format # .. it really did!
def test_image_transcoding(space_resource, format, image_type): """ Test that images get transcoded into JPEG or PNG if they're not JPEG/PNG """ data = get_test_image_data(format=format) ri = ResourceImage( resource=space_resource, sort_order=8, type=image_type, image=ContentFile(data, name="long_horse.%s" % format) ) expected_format = ("PNG" if image_type in ("map", "ground_plan") else "JPEG") ri.full_clean() assert ri.image_format == expected_format # Transcoding occurred assert Image.open(ri.image).format == expected_format # .. it really did!
def test_image_transcoding_bypass(space_resource, format): """ Test that JPEGs and PNGs bypass transcoding """ data = get_test_image_data(format=format) ri = ResourceImage( resource=space_resource, sort_order=8, type="main", image=ContentFile(data, name="nice.%s" % format) ) ri.full_clean() assert ri.image_format == format # Transcoding did not occur assert Image.open(ri.image).format == format # no, no transcoding ri.image.seek(0) # PIL may have `seek`ed or read the stream assert ri.image.read() == data # the bitstream is identical