From 004373034a23fcfe37320dbe94c82a24c6bac262 Mon Sep 17 00:00:00 2001 From: Liam Steckler Date: Sun, 25 Aug 2024 11:58:41 -0700 Subject: [PATCH] Map image improvements --- scl.py | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/scl.py b/scl.py index 0934fa8..34f70b3 100644 --- a/scl.py +++ b/scl.py @@ -11,7 +11,7 @@ from PIL import Image, ImageDraw, ImageFont from sqlalchemy import create_engine, select from sqlalchemy.exc import NoResultFound from sqlalchemy.orm import DeclarativeBase, Mapped, Session, mapped_column -from staticmap import CircleMarker, Polygon, StaticMap +from staticmap import Polygon, StaticMap from geospatial import convert_outage_geometry @@ -45,10 +45,7 @@ class AttribStaticMap(StaticMap, object): super(AttribStaticMap, self)._draw_features(image) txt = Image.new("RGBA", image.size, (255, 255, 255, 0)) - # get a font - # fnt = ImageFont.truetype('FreeMono.ttf', 12) - fnt = ImageFont.load_default() - # get a drawing context + fnt = ImageFont.truetype("fonts/PublicSans-Regular.otf", 24) d = ImageDraw.Draw(txt) textSize = fnt.getbbox(self.attribution) @@ -132,10 +129,11 @@ def do_initial_post( area_text = event["city"] try: map = AttribStaticMap( - 512, - 512, - url_template="https://tiles.stadiamaps.com/tiles/outdoors/{z}/{x}/{y}.png?api_key=" + 1024, + 1024, + url_template="https://tiles.stadiamaps.com/tiles/outdoors/{z}/{x}/{y}@2x.png?api_key=" + stadiamaps_api_key, + tile_size=512, ) assert event["polygons"]["type"] == "polygon" for ring in event["polygons"]["rings"]: @@ -158,16 +156,6 @@ def do_initial_post( # SE Corner assert outage_center.y > 47.2 and outage_center.x < -122 - marker_outline = CircleMarker( - (outage_center.x, outage_center.y), "white", 18 - ) - marker = CircleMarker( - (outage_center.x, outage_center.y), event_class["outage_color"], 12 - ) - - map.add_marker(marker_outline) - map.add_marker(marker) - # Zoom level 17 ensures that we won't get any building/POI names, just street names geocode_url = "{nominatim_url}/reverse?lat={lat}&lon={lon}&format=geocodejson&zoom=17".format( nominatim_url=nominatim_url, @@ -230,7 +218,7 @@ def do_initial_post( map_image = map.render() with io.BytesIO() as map_image_file: - map_image.save(map_image_file, format="PNG", optimize=True) + map_image.save(map_image_file, format="WebP", method=6) map_media_post = mastodon_client.media_post( map_image_file.getvalue(), mime_type="image/png",