def test_multi_frame_resize(): """ImageMagick doesn't handle resizing correctly when a virtual canvas is involved. Make sure we fixed it. """ img = get_image('anim_bgnd.gif') # Original dimensions assert img.size == Size(100, 100) assert img[0].size == Size(32, 32) assert img[0].canvas.position == Vector(5, 10) assert img[1].size == Size(32, 32) assert img[1].canvas.position == Vector(35, 30) assert img[2].size == Size(32, 32) assert img[2].canvas.position == Vector(62, 50) assert img[3].size == Size(32, 32) assert img[3].canvas.position == Vector(10, 55) img = img.resized(img.size * 0.5) # Resized dimensions -- reduced by half assert img.size == Size(50, 50) assert img[0].size == Size(16, 16) assert img[0].canvas.position == Vector(3, 5) assert img[1].size == Size(16, 16) assert img[1].canvas.position == Vector(18, 15) assert img[2].size == Size(16, 16) assert img[2].canvas.position == Vector(31, 25) assert img[3].size == Size(16, 16) assert img[3].canvas.position == Vector(5, 28)
def test_cropped_canvas_fixing_large_crop(): size = Size(20, 20) img = builtins.rose.resized(size) dim = Size(50, 50).at((-25, -25)) cropped = img.cropped(dim) assert cropped.size == size assert cropped[0].canvas == size.at(origin)
def check_original_dimensions(img): assert img.size == Size(100, 100) assert img[0].size == Size(32, 32) assert img[0].canvas.position == Vector(5, 10) assert img[1].size == Size(32, 32) assert img[1].canvas.position == Vector(35, 30) assert img[2].size == Size(32, 32) assert img[2].canvas.position == Vector(62, 50) assert img[3].size == Size(32, 32) assert img[3].canvas.position == Vector(10, 55)
def test_cropped_canvas_fixing(): img = builtins.rose.resized((200, 200)) dim = Size(50, 50).at((25, 25)) cropped = img.cropped(dim) assert cropped.size == dim.size assert cropped[0].canvas == dim.at(origin)
def size(self): """The image dimensions, as a `Size`. Empty images have zero size. Some image formats support a canvas offset, in which case this value may not match the actual drawable area. See `ImageFrame.canvas`. Note that multi-frame images don't have a notion of intrinsic size for the entire image, though particular formats may enforce that every frame be the same size. If the image has multiple frames, this returns the size of the first frame, which is in line with most image-handling software. """ if self._frames: _frame = self._frames[0]._frame # Note that this doesn't use .rows/.columns, as those are the size # of the pixel area. The "page" is the size of the canvas, which # is the size of the image itself. # TODO the canvas might be different between different frames! see # if this happens on load, try to preserve it with operations return Size(_frame.page.width, _frame.page.height) else: return Size(0, 0)
def test_crop_miss(ctx): img = builtins.rose.cropped(Size(40, 30).at((90, 60)), preserve_canvas=True) ctx.compare(img, 'crop_miss.miff')
def test_crop_all(ctx): img = builtins.rose.cropped(Size(90, 60).at((-10, -10)), preserve_canvas=True) ctx.compare(img, 'crop_all.miff')
def test_crop(ctx): img = builtins.rose.cropped(Size(40, 30).at((10, 10)), preserve_canvas=True) ctx.compare(img, 'crop.miff')
def size(self): """Size of the frame, as a `Size`. Shortcut for `frame.canvas.size`. """ return Size(self._frame.columns, self._frame.rows)
def test_rose_pixel(ctx): img = builtins.rose img = img.cropped(Size(1, 1).at((40, 30))) img = img.resized((100, 100), filter='box') ctx.compare(img, 'canvas_pick.miff')