summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2011-07-29 15:33:29 -0600
committerTavian Barnes <tavianator@gmail.com>2011-07-29 15:33:29 -0600
commit0dd2bbbb3953255a11fdbbcfa0e986e7fbb1a2f2 (patch)
treecd8c2c6363cc0c420f2f292dd65cc758569083f7
parent85baaa87134598ec8f4a5720f666b4dd4a7f63ed (diff)
downloaddimension-0dd2bbbb3953255a11fdbbcfa0e986e7fbb1a2f2.tar.xz
Fix region sanity check.
-rw-r--r--dimension/dimension.in14
1 files changed, 8 insertions, 6 deletions
diff --git a/dimension/dimension.in b/dimension/dimension.in
index 9577d51..bb9f012 100644
--- a/dimension/dimension.in
+++ b/dimension/dimension.in
@@ -89,12 +89,14 @@ else:
raise RuntimeError("range specified in invalid format.")
_args.region_x = int(_match.group(1))
_args.region_y = int(_match.group(2))
- _args.region_width = int(_match.group(3)) - _args.region_x
- _args.region_height = int(_match.group(4)) - _args.region_y
- if _args.region_x + _args.region_width >= _args.width:
- raise RuntimeError("region exceeds width of image.")
- if _args.region_y + _args.region_height >= _args.height:
- raise RuntimeError("region exceeds height of image.")
+ _region_xmax = int(_match.group(3))
+ _region_ymax = int(_match.group(4))
+ _args.region_width = _region_xmax - _args.region_x
+ _args.region_height = _region_ymax - _args.region_y
+ if _args.region_width <= 0 or _args.region_height <= 0:
+ raise RuntimeError("region is degenerate.")
+ if _region_xmax >= _args.width or _region_ymax > _args.height:
+ raise RuntimeError("region exceeds bounds of image.")
# Default output is basename(input).png
if _args.output is None: