paritybit.ca

Raw content of https://www.paritybit.ca.
git clone https://git.sr.ht/~jbauer/paritybit.ca
Log | Files | Refs | README | LICENSE

monitor-dpi-calculator.md (1240B)


      1 Title: Monitor DPI Calculator
      2 Summary: Calculate your monitor's DPI.
      3 
      4 # [%title]
      5 
      6 <noscript>It seems that the current browser you are using does not support
      7 JavaScript or it has been disabled. JavaScript is required for this utility to
      8 function.</noscript>
      9 
     10 Input the resolution and size of a screen to calculate its DPI/PPI.
     11 
     12 <p><strong>Result:</strong> <span id="result-field">0.00</span> DPI</p>
     13 
     14 <form>
     15     <input id="width" type="number" min="0" placeholder="1920" arial-label="Resolution Width"/>pixels<br>
     16     <input id="height" type="number" min="0" placeholder="1080" aria-label="Resolution Height"/>pixels<br>
     17     <input id="size" type="number" min="0" placeholder="0" aria-label="Monitor Size"/>inches<br>
     18     <button type="button" onClick=calculate()>Calculate</button>
     19 </form>
     20 
     21 <script>
     22 function calculate() {
     23 	let width = document.getElementById("width").value;
     24 	let height = document.getElementById("height").value;
     25 	let size = document.getElementById("size").value;
     26 
     27 	if (width <= 0 || height <= 0 || size <= 0) {
     28 		alert("Please enter a valid number greater than 0!");
     29 		return;
     30 	}
     31 
     32 	dpi = Math.sqrt(width * width + height * height) / size;
     33 
     34 	document.getElementById("result-field").innerHTML = dpi.toFixed(2);
     35 }
     36 </script>