Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save juanluisrto/8febbd009f1bf4cc9bb811843dc63ae9 to your computer and use it in GitHub Desktop.
Save juanluisrto/8febbd009f1bf4cc9bb811843dc63ae9 to your computer and use it in GitHub Desktop.
from math import atan2, degrees, radians, sin, cos
def fit_text_as_geometry_between_two_points(text, A, B):
mid_coords = ((B[1] + A[1])/2, (B[0] + A[0])/2)
angle = atan2(B[1] - A[1], B[0] - A[0])
bbox = LineString([A,B]).bounds
h = get_height(bbox)
w = get_width(bbox)
scale_factor = 100*(abs(h*sin(angle)) + abs(w*cos(angle)))
ml = text_as_geometry(text, mid_coords, scale_factor, degrees(angle))
return ml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment