Skip to content

Instantly share code, notes, and snippets.

@harpwood
Created March 8, 2023 15:24
Show Gist options
  • Save harpwood/ff6429eb9b6e4481dd5d4ae50140cee4 to your computer and use it in GitHub Desktop.
Save harpwood/ff6429eb9b6e4481dd5d4ae50140cee4 to your computer and use it in GitHub Desktop.
Converts a length in centimeters to the equivalent length in pixels, based on the current display's DPI.
/**
* Converts a length in centimeters to the equivalent length in pixels, based on the current display's DPI.
* @param {number} cm - The length in centimeters to convert to pixels.
* @returns {number} The equivalent length in pixels.
*
* @author Written by Gkri (Harpwood studio)
* @license MIT License https://opensource.org/licenses/MIT
*/
function display_centimeters_to_pixel(cm) {
return max(display_get_dpi_x(), display_get_dpi_y()) * cm / 2.54;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment