1
0
mirror of synced 2024-11-28 07:50:51 +01:00

Implement a way to force particular width/height instead of just a particular scaling factor.

This commit is contained in:
Jennifer Taylor 2021-06-13 21:38:41 +00:00
parent 092c4b6972
commit 07205d3e16
2 changed files with 24 additions and 7 deletions

View File

@ -64,7 +64,7 @@ class Point:
} }
def as_tuple(self) -> Tuple[int, int]: def as_tuple(self) -> Tuple[int, int]:
return (int(self.x), int(self.y)) return (int(round(self.x, 5)), int(round(self.y, 5)))
def add(self, other: "Point") -> "Point": def add(self, other: "Point") -> "Point":
x = self.x + other.x x = self.x + other.x

View File

@ -526,6 +526,8 @@ def render_path(
enable_anti_aliasing: bool = False, enable_anti_aliasing: bool = False,
background_color: Optional[str] = None, background_color: Optional[str] = None,
background_image: Optional[str] = None, background_image: Optional[str] = None,
force_width: Optional[int] = None,
force_height: Optional[int] = None,
force_aspect_ratio: Optional[str] = None, force_aspect_ratio: Optional[str] = None,
scale_width: float = 1.0, scale_width: float = 1.0,
scale_height: float = 1.0, scale_height: float = 1.0,
@ -571,8 +573,8 @@ def render_path(
# Calculate the size of the SWF so we can apply scaling options. # Calculate the size of the SWF so we can apply scaling options.
swf_location = renderer.compute_path_location(path) swf_location = renderer.compute_path_location(path)
requested_width = swf_location.width requested_width = force_width if force_width is not None else swf_location.width
requested_height = swf_location.height requested_height = force_height if force_height is not None else swf_location.height
# Allow overriding the aspect ratio. # Allow overriding the aspect ratio.
if force_aspect_ratio: if force_aspect_ratio:
@ -603,6 +605,7 @@ def render_path(
else: else:
requested_height = new_height requested_height = new_height
# Finally, apply requested final scaling.
requested_width *= scale_width requested_width *= scale_width
requested_height *= scale_height requested_height *= scale_height
@ -908,23 +911,35 @@ def main() -> int:
default=None, default=None,
help="Only render these frames. Can provide either a number or a comma-separated list of numbers, or a range such as 10-20.", help="Only render these frames. Can provide either a number or a comma-separated list of numbers, or a range such as 10-20.",
) )
render_parser.add_argument(
"--force-width",
type=int,
default=None,
help="Force the width of the rendered image to a specific pixel value, such as 640 or 800.",
)
render_parser.add_argument(
"--force-height",
type=int,
default=None,
help="Force the height of the rendered image to a specific pixel value, such as 480 or 600.",
)
render_parser.add_argument( render_parser.add_argument(
"--force-aspect-ratio", "--force-aspect-ratio",
type=str, type=str,
default=None, default=None,
help="Force the aspect ratio of the rendered image, as a colon-separated aspect ratio such as 16:9 or 4:3.", help="Force the aspect ratio of the rendered image, as a colon-separated aspect ratio such as 16:9 or 4:3, after applying any forced width and height.",
) )
render_parser.add_argument( render_parser.add_argument(
"--scale-width", "--scale-width",
type=float, type=float,
default=1.0, default=1.0,
help="Scale the width of the animation by some factor, such as 2.0 or 0.5.", help="Scale the final width of the animation by some factor, such as 2.0 or 0.5, after applying any forced width, height and aspect ratio.",
) )
render_parser.add_argument( render_parser.add_argument(
"--scale-height", "--scale-height",
type=float, type=float,
default=1.0, default=1.0,
help="Scale the height of the animation by some factor, such as 2.0 or 0.5.", help="Scale the final height of the animation by some factor, such as 2.0 or 0.5, after applying any forced width, height and aspect ratio.",
) )
render_parser.add_argument( render_parser.add_argument(
"--disable-threads", "--disable-threads",
@ -934,7 +949,7 @@ def main() -> int:
render_parser.add_argument( render_parser.add_argument(
"--enable-anti-aliasing", "--enable-anti-aliasing",
action="store_true", action="store_true",
help="Enable experimental anti-aliased rendering.", help="Enable anti-aliased rendering, using bilinear interpolation and super-sampling depending on the circumstance.",
) )
render_parser.add_argument( render_parser.add_argument(
"-v", "-v",
@ -1003,6 +1018,8 @@ def main() -> int:
enable_anti_aliasing=args.enable_anti_aliasing, enable_anti_aliasing=args.enable_anti_aliasing,
background_color=args.background_color, background_color=args.background_color,
background_image=args.background_image, background_image=args.background_image,
force_width=args.force_width,
force_height=args.force_height,
force_aspect_ratio=args.force_aspect_ratio, force_aspect_ratio=args.force_aspect_ratio,
scale_width=args.scale_width, scale_width=args.scale_width,
scale_height=args.scale_height, scale_height=args.scale_height,