Example #1
0
     $width = $mat[1];
     $height = $mat[2];
 } else {
     $width = 200;
     $height = 200;
     $text = $width . 'x' . $height;
 }
 if ($width < 1 || $height < 1) {
     die("too small!");
 }
 $area = $width * $height;
 if ($area >= 16000000 || $width > 9999 || $height > 9999) {
     die("to big!");
 }
 $newbg = color2rgb($bg);
 $newcolor = color2rgb($color);
 $font = 'wqy-microhei.ttc';
 $text_angle = 0;
 $fontsize = max(min($width / strlen($text) * 1.15, $height * 0.5), 5);
 $text = mb_convert_encoding(urldecode($text), "UTF-8", "auto");
 $rect = ImageTTFBBox($fontsize, 0, $font, $text);
 $a = deg2rad($text_angle);
 $ca = cos($a);
 $sa = sin($a);
 $ret = array();
 for ($i = 0; $i < 7; $i += 2) {
     $ret[$i] = round($rect[$i] * $ca + $rect[$i + 1] * $sa);
     $ret[$i + 1] = round($rect[$i + 1] * $ca - $rect[$i] * $sa);
 }
 $textWidth = ceil(($ret[4] - $ret[1]) * 1.07);
 $textHeight = ceil((abs($ret[7]) + abs($ret[1])) * 1);
Example #2
0
function imagefilledellipseaa(&$im, $CX, $CY, $Width, $Height, $color)
{
    $XRadius = floor($Width / 2);
    $YRadius = floor($Height / 2);
    $baseColor = color2rgb($color);
    $TwoASquare = 2 * $XRadius * $XRadius;
    $TwoBSquare = 2 * $YRadius * $YRadius;
    $X = $XRadius;
    $Y = 0;
    $XChange = $YRadius * $YRadius * (1 - 2 * $XRadius);
    $YChange = $XRadius * $XRadius;
    $EllipseError = 0;
    $StoppingX = $TwoBSquare * $XRadius;
    $StoppingY = 0;
    $alpha = 77;
    $color = imagecolorexactalpha($im, $baseColor[0], $baseColor[1], $baseColor[2], $alpha);
    while ($StoppingX >= $StoppingY) {
        imagefilledellipseaa_Plot4EllipsePoints($im, $CX, $CY, $X, $Y, $color, 0);
        $Y++;
        $StoppingY += $TwoASquare;
        $EllipseError += $YChange;
        $YChange += $TwoASquare;
        if (2 * $EllipseError + $XChange > 0) {
            $X--;
            $StoppingX -= $TwoBSquare;
            $EllipseError += $XChange;
            $XChange += $TwoBSquare;
        }
        $filled = $X - sqrt($XRadius * $XRadius - $XRadius * $XRadius / ($YRadius * $YRadius) * $Y * $Y);
        $alpha = abs(90 * $filled + 37);
        imagecolordeallocate($im, $color);
        $color = imagecolorexactalpha($im, $baseColor[0], $baseColor[1], $baseColor[2], $alpha);
    }
    $X = 0;
    $Y = $YRadius;
    $XChange = $YRadius * $YRadius;
    $YChange = $XRadius * $XRadius * (1 - 2 * $YRadius);
    $EllipseError = 0;
    $StoppingX = 0;
    $StoppingY = $TwoASquare * $YRadius;
    $alpha = 77;
    $color = imagecolorexactalpha($im, $baseColor[0], $baseColor[1], $baseColor[2], $alpha);
    while ($StoppingX <= $StoppingY) {
        imagefilledellipseaa_Plot4EllipsePoints($im, $CX, $CY, $X, $Y, $color, 1);
        $X++;
        $StoppingX += $TwoBSquare;
        $EllipseError += $XChange;
        $XChange += $TwoBSquare;
        if (2 * $EllipseError + $YChange > 0) {
            $Y--;
            $StoppingY -= $TwoASquare;
            $EllipseError += $YChange;
            $YChange += $TwoASquare;
        }
        $filled = $Y - sqrt($YRadius * $YRadius - $YRadius * $YRadius / ($XRadius * $XRadius) * $X * $X);
        $alpha = abs(90 * $filled + 37);
        imagecolordeallocate($im, $color);
        $color = imagecolorexactalpha($im, $baseColor[0], $baseColor[1], $baseColor[2], $alpha);
    }
}