Skip to content

Commit

Permalink
Merge pull request #548 from thegreenwebfoundation/hs-green-badge-reb…
Browse files Browse the repository at this point in the history
…rand

Hs green badge rebrand
  • Loading branch information
hanopcan authored Jan 26, 2024
2 parents 3f70248 + 3deabab commit d230929
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 37 deletions.
54 changes: 17 additions & 37 deletions apps/greencheck/api/legacy_image_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,14 @@
from ..domain_check import GreenDomainChecker
from ..models import GreenDomain

GREEN_DOMAIN_TEXT_COLOR = (00, 70, 00)
GREEN_DOMAIN_TEXT_SHADOW = (79, 138, 74)
GREEN_HOSTED_BY_TEXT_COLOR = (255, 255, 255)
GREEN_HOSTED_BY_SHADOW_COLOR = (93, 173, 19)

GREY_DOMAIN_TEXT_COLOR = (100, 100, 100)
GREY_DOMAIN_TEXT_SHADOW = (170, 170, 170)
GREY_HOSTED_BY_TEXT_COLOR = (255, 255, 255)
GREY_HOSTED_BY_TEXT_SHADOW = (210, 210, 210)
TEXT_COLOR = (0, 0, 0)
TEXT_POSITION_LEFT = 15

app_dir = Path(__file__).parent.parent
font_path = app_dir / "badges" / "OpenSans-Regular.ttf"
domain_font = ImageFont.truetype(str(font_path), 14)
hosted_by_font = ImageFont.truetype(str(font_path), 11)
font_path = app_dir / "badges" / "TWKEverett-Regular.otf"

font_settings_green = ImageFont.truetype(str(font_path), 9)
font_settings_grey = ImageFont.truetype(str(font_path), 9)

logger = logging.getLogger(__name__)
checker = GreenDomainChecker()
Expand Down Expand Up @@ -60,31 +54,18 @@ def fetch_template_image(domain, green=False) -> Image:
return img


def add_domain_text(draw, domain, text_color, text_shadow):
left_inside_block = (18, 80)
left_inside_block_offset = (17, 79)

draw.text(left_inside_block_offset, f"{domain}", text_shadow, font=domain_font)
draw.text(left_inside_block, f"{domain}", text_color, font=domain_font)


def add_hosted_text(draw, text_color, text_shadow, provider=None, green=False):

left_inside_block = (18, 100)
left_inside_block_offset = (18, 100)
def add_hosted_text(draw, text_color, domain, provider=None, green=False):

if green:
if provider:
hosted_by_message = f"is green hosted by {provider}."
draw.text((TEXT_POSITION_LEFT, 43), f"{domain}", TEXT_COLOR, font=font_settings_green)
hosted_by_message = f"hosted by {provider}"
draw.text((TEXT_POSITION_LEFT, 55), hosted_by_message, text_color, font=font_settings_green)
else:
hosted_by_message = "is hosted green."
draw.text((TEXT_POSITION_LEFT, 54), f"{domain}", TEXT_COLOR, font=font_settings_green)
else:
hosted_by_message = "is hosted grey"
draw.text((TEXT_POSITION_LEFT, 54), f"{domain}", TEXT_COLOR, font=font_settings_grey)

draw.text(
left_inside_block_offset, hosted_by_message, text_shadow, font=hosted_by_font
)
draw.text(left_inside_block, hosted_by_message, text_color, font=hosted_by_font)


def annotate_img(img, domain, green=False, provider=None) -> Image:
Expand All @@ -94,21 +75,20 @@ def annotate_img(img, domain, green=False, provider=None) -> Image:
draw = ImageDraw.Draw(img)

if green:
add_domain_text(draw, domain, GREEN_DOMAIN_TEXT_COLOR, GREEN_DOMAIN_TEXT_SHADOW)

add_hosted_text(
draw,
GREEN_HOSTED_BY_TEXT_COLOR,
GREEN_HOSTED_BY_SHADOW_COLOR,
TEXT_COLOR,
domain,
provider=provider,
green=True,
)
return img
else:
add_domain_text(draw, domain, GREY_DOMAIN_TEXT_COLOR, GREY_DOMAIN_TEXT_SHADOW)
add_hosted_text(
draw,
GREY_HOSTED_BY_TEXT_COLOR,
GREY_HOSTED_BY_TEXT_SHADOW,
TEXT_COLOR,
domain,
provider=provider,
green=False,
)
Expand Down
Binary file removed apps/greencheck/badges/ClearSans-Regular.ttf
Binary file not shown.
Binary file removed apps/greencheck/badges/OpenSans-Regular.ttf
Binary file not shown.
Binary file added apps/greencheck/badges/TWKEverett-Regular.otf
Binary file not shown.
Binary file modified apps/greencheck/badges/blank-badge-green.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified apps/greencheck/badges/blank-badge-grey.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d230929

Please sign in to comment.