Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rotate text from the centroid of the bounding box #682

Open
jacebrowning opened this issue Feb 16, 2022 · 0 comments
Open

Rotate text from the centroid of the bounding box #682

jacebrowning opened this issue Feb 16, 2022 · 0 comments

Comments

@jacebrowning
Copy link
Owner

This will match how overlay images are rotated:

memegen/app/utils/images.py

Lines 188 to 201 in a678738

# This offset math is inexact, but works well enough to see
# approximately where rotated overlay images will be placed.
# TODO: implement a proper solution using trigonometry.
angle = abs(overlay.angle)
if angle > 45:
angle = 90 - angle
offset = (
int(angle + (22.5 - angle) / 22.5 - 1),
int(angle + (22.5 - angle) / 22.5 - 1),
)
x1, y1, _x2, _y2 = overlay.get_box(image.size)
point = (x1 - offset[0], y1 - offset[1])
box = box.rotate(overlay.angle, expand=True)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant