Last active
December 10, 2015 13:48
-
-
Save rodrigopandini/4443135 to your computer and use it in GitHub Desktop.
Create horizontal(1000x16) and vertical(16x1000) images of rules (measured in pixels) to be used in, for example, online editors, using PHP and ImageMagick. (inspiration: http://www.ibm.com/developerworks/br/linux/library/l-pixelruler/index.html)
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
<?php | |
$rule1 = "img/rule1.jpg"; | |
$ruleV = "img/ruleV.jpg"; | |
$ruleH = "img/ruleH.jpg"; | |
$width = 1000; | |
$height = 1000; | |
// horizontal rule | |
$str = "line 0,0 $width,0 line 0,15 $width,15"; | |
$text = ""; | |
for ($i = 0; $i <= $width; $i += 5){ | |
$str .= "line $i,12 $i,15 "; | |
} | |
for ($i = 0; $i <= $width; $i += 10){ | |
$str .= "line $i,10 $i,15 "; | |
} | |
for ($i = 0; $i <= $width; $i += 50){ | |
$str .= "line $i,0 $i,15 "; | |
} | |
for ($i = 0; $i <= $width; $i += 50){ | |
$text .= "-draw \"text ".($i+2).",9 '$i' \" "; | |
} | |
$str01 = "convert -size ".$width."x16 xc:white $rule1"; | |
$str02 = "convert -fill black -draw \"$str\" -font arial -pointsize 10 $text $rule1 $ruleH"; | |
exec ($str01); | |
exec ($str02); | |
// vertical rule | |
$str = "line 0,0 0,$height line 15,0 15,$height"; | |
$text = ""; | |
for ($i = 0; $i <= $height; $i += 5){ | |
$str .= "line 12,$i 15,$i "; | |
} | |
for ($i = 0; $i <= $height; $i += 10){ | |
$str .= "line 10,$i 15,$i "; | |
} | |
for ($i = 0; $i <= $height; $i += 50){ | |
$str .= "line 0,$i 15,$i "; | |
} | |
for ($i = 0; $i <= $height; $i += 50){ | |
$c = strval($i); | |
$a = str_split($c); | |
for ($j = 0; $j < count($a); $j++) { | |
$text .= "-draw \"text 3,".($i+9 + $j*8)." '$a[$j]' \" ";; | |
} | |
} | |
$str01 = "convert -size 16x".$height." xc:white $rule1"; | |
$str02 = "convert -fill black -draw \"$str\" -font arial -pointsize 10 $text $rule1 $ruleV"; | |
exec ($str01); | |
exec ($str02); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment