Skip to content

Instantly share code, notes, and snippets.

@PaulGoldschmidt
Created December 4, 2023 00:02
Show Gist options
  • Save PaulGoldschmidt/53353df4a81c14d032615f25ab837855 to your computer and use it in GitHub Desktop.
Save PaulGoldschmidt/53353df4a81c14d032615f25ab837855 to your computer and use it in GitHub Desktop.
Calculating the resolution needed to fill a canvas from mm with a given DPI.
# Convert millimeters to inches and then to pixels at given DPI
# Dimensions in millimeters
width_mm = 420
height_mm = 594
# Conversion factor from mm to inches
mm_to_inch = 1 / 25.4
# Convert dimensions to inches
width_inch = width_mm * mm_to_inch
height_inch = height_mm * mm_to_inch
# DPI value
dpi = 300
# Convert dimensions to pixels
width_px = width_inch * dpi
height_px = height_inch * dpi
(width_px, height_px)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment