def get_or_add_image_part(self, image_descriptor): """Return |ImagePart| object containing image identified by *image_descriptor*. The image-part is 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_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.content_type == content_type assert image.ext == ext 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_can_construct_from_an_image_file_like(self, from_filelike_fixture): image_stream, _from_stream_, blob, image_ = from_filelike_fixture image = Image.from_file(image_stream) _from_stream_.assert_called_once_with(image_stream, blob, None) assert image is image_
def it_can_construct_from_an_image_path(self, from_path_fixture): image_path, _from_stream_, stream_, blob, filename, image_ = ( from_path_fixture) image = Image.from_file(image_path) _from_stream_.assert_called_once_with(stream_, blob, filename) assert image is image_