コード例 #1
0
 */
function color_cache($im, $color)
{
    global $color_cache;
    if (!isset($color_cache[$color[0] . '_' . $color[1] . '_' . $color[2]])) {
        $color_cache[$color[0] . '_' . $color[1] . '_' . $color[2]] = imagecolorallocate($im, $color[0], $color[1], $color[2]);
    }
    return $color_cache[$color[0] . '_' . $color[1] . '_' . $color[2]];
}
function drawText($im, $name, $size = 11)
{
    doDrawText($im, $name, $size, array(237, 223, 191));
    //doDrawText ($im, $name, $size, array (255, 255, 255));
}
function doDrawText($im, $name, $size, $color = array(255, 255, 255))
{
    $font = BASE_PATH . 'static/fonts/slogan.ttf';
    $color = imagecolorallocate($im, $color[0], $color[1], $color[2]);
    $fontsize = imagettfbbox($size, 0, $font, $name);
    $width = $fontsize[2] - $fontsize[0];
    $dim = IMG_WIDTH / IMG_HEIGHT;
    if ($dim > 2) {
        // Right bottom
        $dest = array(floor(IMG_WIDTH - $width) - 5, IMG_HEIGHT - 13 + $size / 2);
    } else {
        // Center bottom
        $dest = array(floor(IMG_WIDTH / 2 - $width / 2), IMG_HEIGHT - 18 + $size / 2);
    }
    imagettftext($im, $size, 0, $dest[0], $dest[1], $color, $font, $name);
}
define('IMG_WIDTH', isset($_GET['width']) ? (int) $_GET['width'] : 800);