Created
March 20, 2025 12:42
-
-
Save erikchan002/d32eb727490d34cf03da9ecbc634a63e to your computer and use it in GitHub Desktop.
Focal Length Visualizer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image, ImageDraw, ImageFont, ImageColor | |
from operator import itemgetter | |
canon_red = "#CC0000" | |
nikon_yellow = "#FFE100" | |
fuji_green = "#01916d" | |
sony_black = "#000000" | |
path = r"250.jpeg" | |
original = (250,canon_red) | |
focal_lengths = sorted([ | |
(600,nikon_yellow), | |
(300,fuji_green), | |
(400,sony_black) | |
],key=itemgetter(0),reverse=True) | |
scale = 0.1 | |
font_size = 200*scale | |
img = Image.open(path) | |
w,h = img.size | |
w=int(w*scale) | |
h=int(h*scale) | |
img = img.resize((w,h)) | |
draw = ImageDraw.Draw(img) | |
original_focal_length,original_color = original | |
draw.rectangle([(0,0),(w-1,h-1)], outline=original_color, width=2) | |
draw.text((w-5,5),f"{original_focal_length}mm",anchor="rt",font=ImageFont.truetype("Arial", font_size),fill=original_color) | |
for focal_length,color in focal_lengths: | |
draw.rectangle([((w-w*original_focal_length/focal_length)//2,(h-h*original_focal_length/focal_length)//2),((w+w*original_focal_length/focal_length)//2,(h+h*original_focal_length/focal_length)//2)], outline=color, width=2) | |
draw.text(((w+w*original_focal_length/focal_length)//2-5,(h-h*original_focal_length/focal_length)//2+5),f"{focal_length}mm",anchor="rt",font=ImageFont.truetype("Arial", font_size),fill=color) | |
img.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment