diff --git a/src/pixie/images.nim b/src/pixie/images.nim index e4f447f..55db070 100644 --- a/src/pixie/images.nim +++ b/src/pixie/images.nim @@ -129,6 +129,12 @@ proc subImage*(image: Image, x, y, w, h: int): Image {.raises: [PixieError].} = w * 4 ) +proc subImage*(image: Image, rect: Rect): Image {.raises: [PixieError].} = + ## Gets a sub image from this image via rectangle. + ## Rectangle is snapped/expanded to whole pixels first. + let r = rect.snapToPixels() + image.subImage(r.x.int, r.y.int, r.w.int, r.h.int) + proc diff*(master, image: Image): (float32, Image) {.raises: [PixieError].} = ## Compares the parameters and returns a score and image of the difference. let diff --git a/tests/test_images.nim b/tests/test_images.nim index 5117df1..bb86a6f 100644 --- a/tests/test_images.nim +++ b/tests/test_images.nim @@ -259,5 +259,5 @@ block: ) let rect = image.opaqueBounds() doAssert rect == rect(6.0, 6.0, 48.0, 48.0) - let trimmedImage = image.subImage(rect.x.int, rect.y.int, rect.w.int, rect.h.int) + let trimmedImage = image.subImage(rect) trimmedImage.xray("tests/images/opaqueBounds.png")