Posted By

rogalski on 03/04/11


Tagged

css fonts


Versions (?)

Calculate Font Sizes


 / Published in: PHP
 

URL: http://www.codingforums.com/showthread.php?t=204303

  1. <?php
  2. $parts = 6; // dont change, h1 to h6
  3. $base_size = 12; //font-size inherited by parent element, just to see how much pixels the headings will be :)
  4. $base_lh = 1.5; //line-height in em
  5. $max_size = 300; //maximum font-size in percent (h1)
  6. $min_size = 100; //minimum font-size in percent (h6)
  7.  
  8. $percent_per_part = 1 / ($parts -1);
  9. $outputstring = 'h%d { margin-bottom:%sem; line-height:%sem; font-size:%s%%; /'.'* %spx *'.'/ }<br>';
  10.  
  11. $output = '';
  12. for($i=1;$i<$parts+1;$i++) {
  13. $y = 1 - (($i - 1) * $percent_per_part);
  14. $percent = (pow($y,2) * ($max_size - $min_size)) + $min_size;
  15. $mult = $percent / 100;
  16. $px = $mult * $base_size;
  17. $lh = $base_lh / $mult;
  18. $output .= sprintf($outputstring, $i, number_format($lh, 3, '.', ''), number_format($lh, 3, '.', ''), $percent, number_format($px, 1, '.', ''));
  19. }
  20. echo $output.'<br><br>';
  21. ?>

Report this snippet  

You need to login to post a comment.