Skip to content

Instantly share code, notes, and snippets.

@weslly
Created September 24, 2012 19:35
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save weslly/3777870 to your computer and use it in GitHub Desktop.
Generate line numbers to Sublime VintageLines plugin
<?php
// Set the content-type
header('Content-Type: image/png');
// Replace with your own font and font-size
$font = 'UbuntuMono-R.ttf';
$fontsize = 11;
// Create the numbers directory if it doesn't exist
if(!is_dir(dirname(__FILE__) . '/numbers/')) {
mkdir(dirname(__FILE__) . '/numbers/', 777);
}
for ($i = 0; $i <= 80; $i++) {
$text = ($i <= 9)? ' ' . $i : $i;
$im = imagecreatetruecolor(16, 16);
imagealphablending($im, true);
// Create some colors
$white = imagecolorallocatealpha($im, 255, 255, 255, 0);
$transp = imagecolorallocatealpha($im, 0, 0, 0, 127);
// $grey = imagecolorallocate($im, 128, 128, 128);
// $black = imagecolorallocate($im, 0, 0, 0);
imagefill($im, 0, 0, $transp);
imagesavealpha($im, true);
imagettftext($im, $fontsize, 0, 1, 11, $white, $font, $text);
$imagepath = 'numbers/' . $i . '.png';
imagepng($im, $imagepath);
readfile($imagepath);
imagedestroy($im);
}
?>
@weslly
Copy link
Author

weslly commented Sep 25, 2012

Example (using ubuntu mono):
Screenshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment