def it_can_construct_from_an_image_stream(self): image_file_path = test_file('monty-truth.png') with open(image_file_path, 'rb') as image_file_stream: image = Image.from_file(image_file_stream) assert isinstance(image, Image) assert image.sha1 == '79769f1e202add2e963158b532e36c2c0f76a70c' assert image.filename == 'image.png'
def get_or_add_image_part(self, image_descriptor): """ Return an |ImagePart| instance containing the image identified by *image_descriptor*, newly created if a matching one is not present in the collection. """ image = Image.from_file(image_descriptor) matching_image_part = self._get_by_sha1(image.sha1) if matching_image_part is not None: return matching_image_part return self._add_image_part(image)
def it_correctly_characterizes_a_few_known_images(self, known_image_fixture): image_path, characteristics = known_image_fixture ext, content_type, px_width, px_height, horz_dpi, vert_dpi = ( characteristics) with open(test_file(image_path), 'rb') as stream: image = Image.from_file(stream) assert image.ext == ext assert image.content_type == content_type assert image.px_width == px_width assert image.px_height == px_height assert image.horz_dpi == horz_dpi assert image.vert_dpi == vert_dpi
def dimensions_fixture(self, request): image_file_path = test_file('monty-truth.png') image = Image.from_file(image_file_path) expected_cx, expected_cy = 1905000, 2717800 # case 1: image part is loaded by PartFactory w/no Image inst if request.param == 'loaded': partname = PackURI('/word/media/image1.png') content_type = CT.PNG image_part = ImagePart.load(partname, content_type, image.blob, None) # case 2: image part is newly created from image file elif request.param == 'new': image_part = ImagePart.from_image(image, None) return image_part, expected_cx, expected_cy
def it_knows_the_extension_of_a_stream_based_image(self): image_file_path = test_file('monty-truth.png') with open(image_file_path, 'rb') as image_file_stream: image = Image.from_file(image_file_stream) assert image.ext == '.png'
def it_knows_the_extension_of_a_file_based_image(self): image_file_path = test_file('monty-truth.png') image = Image.from_file(image_file_path) assert image.ext == '.png'
def it_can_construct_from_an_image_path(self): image_file_path = test_file('monty-truth.png') image = Image.from_file(image_file_path) assert isinstance(image, Image) assert image.sha1 == '79769f1e202add2e963158b532e36c2c0f76a70c' assert image.filename == 'monty-truth.png'