Code Dump: Icongen

Here’s a quick and dirty php script (using GD) that creates icons for my android phone. I got fed up at SimpleText, which no longer creates transparent images, and appears to have been abandoned by its developer. Images are created from the URL

icongen.php?name=ICON

into a folder called images.

<!--?php &lt;br ?--> $img_width=128;
$img_height=128;
$handle = ImageCreatetruecolor ($img_width,$img_height) or die ("Cannot Create image");
$bg_color = ImageColorAllocate ($handle, 0,0,0);
$black = ImageColorAllocate ($handle, 0,0,0);
$white = ImageColorAllocate ($handle, 255,255,255);
$red = ImageColorAllocate ($handle, 255,0,0);
$blue = ImageColorAllocate ($handle, 50,50,150);
$txt_color = $black;
imagecolortransparent($handle,$bg_color);
$font_size = 26;
$font_path='./OpenSans-Regular.ttf';
$txt_max_width = intval(0.8 * $img_width);
if($_GET['name']) { $text=$_GET['name'];
} else { $text='snap';
} #do { #$font_size++;
$p = imagettfbbox($font_size,0,$font_path,$text);
$txt_width=$p[2]-$p[0];
#} while ($txt_width &lt;= $txt_max_width); $y = $img_height * 0.57; // baseline of text at 90% of $img_height $x = ($img_width - $txt_width) / 2; imagettftext($handle, $font_size, 0,$x, $y, $white, $font_path, $text); ImagePng ($handle,'images/'.$text.'.png'); imagedestroy($handle); ?&gt;<img src="images/&lt;?php" />.png&gt;

OSHA Label Generator

http://michaellubert.com/blog/wp-content/uploads/2013/11/label.png

[OSHA Label Generator](http://michaellubert.com/projects/labeler “OSHA Label Generator”)
This is something I whipped up yesterday afternoon/this morning after an employee requested I help him create a template for OSHA labels, as apparently OSHA standards have changed or something. As he described what he wanted, I knew that it would be painful to create in Word, and it’d be awful to use and attempt to get everything in place, aligned, and to add the necessary icons. My way isn’t the simpler way, but it a better way.