Generated Portrait Placeholders
Today, I finished a script that generates thumbnail-sized images. The images are just solid fills of the web-safe colors. These images will be used as placeholders so that I can begin developing the MG game. I'll be able to work out the kinks of the game this way. Right now, the script creates PNGs, but I can easily change it to create JPGs.
The script used a Pear library called Image_Canvas. Here is the script, called gen_profile_images.php:
The script used a Pear library called Image_Canvas. Here is the script, called gen_profile_images.php:
<?php
// profile pic gen
require_once "../include.php"; // pear path
require_once "Image/Canvas.php";
require_once "Image/Canvas/GD.php";
require_once "Image/Canvas/GD/PNG.php";
echo "test";
$possible = str_split("123456789ABCDEF");
$pairs = array();
foreach ( $possible as $chr ) {
$pairs [] = "$chr$chr";
}
$colors = array();
for ( $i = 0 ; $i < count($pairs); $i++ ) {
for ( $j = 0 ; $j < count($pairs); $j++ ) {
for ( $k = 0 ; $k < count($pairs); $k++ ) {
$colors[] = "{$pairs[$i]}{$pairs[$j]}{$pairs[$k]}";
}
}
}
echo "generated ".count($colors)." colors";
foreach ( $colors as $color ) {
$width = 100;
$height = 150;
$fillColor = "#$color";
$fn = "$color.png";
$canvas = new Image_Canvas_GD_PNG(
array (
"width" =>$width,
"height" =>$height,
"left" =>0,
"top" =>0)
);
$canvas->rectangle (
array (
"x0" => 0,
"y0" => 0,
"x1" => $width,
"y1" => $height,
"fill" => $fillColor)
);
$canvas->save ( array( "filename" => "images/$fn" ));
//echo "Saved image $fn";
}
?>
0 Comments:
Post a Comment
<< Home