App-Widget

 view release on metacpan or  search on metacpan

cgi-bin/app-button  view on Meta::CPAN

    $corner = 6 if (!defined $corner);

    # Black Outline
    $im->line($corner+1      ,1        ,$width-$corner,1        ,&color("#000000"));  # top
    $im->line($corner        ,1        ,0             ,$corner+1,&color("#000000"));  # top-left corner
    $im->line(0              ,$height-3,0             ,$corner+1,&color("#000000"));  # left
    $im->line($width-$corner ,1        ,$width-1      ,$corner  ,&color("#000000"));  # top-right corner

    # White inscribed line
    $im->line($corner+1      ,2        ,$width-$corner,2        ,&color("#ffffff"));  # top
    $im->line($corner+1      ,2        ,1             ,$corner+1,&color("#ffffff"));  # top-left corner
    $im->line(1              ,$height-1,1             ,$corner+1,&color("#ffffff"));  # left
    $im->line(0              ,$height-1,0             ,$height-2,&color("#ffffff"));  # bottom left
    $im->line($width-1       ,$height-1,$width-1      ,$height-2,&color("#ffffff"));  # bottom left

    # Gray shadow
    $im->line($width-$corner ,2        ,$width-1      ,$corner+1,&color("#888888"));  # top-right corner
    $im->line($width-1       ,$corner+1,$width-1      ,$height-3,&color("#888888"));  # right

    if ($selected) {
        $fontsize += 2;
    }
    else {
        $im->line(0              ,$height-1,$width-1      ,$height-1,&color("#ffffff"));  # bottom
        $im->line(0              ,$height-2,$width-1      ,$height-2,&color("#ffffff"));  # bottom
        $im->line(0              ,$height-3,$width-1      ,$height-3,&color("#000000"));  # bottom line
    }

    if (defined $fontname && $fontname ne "" && $fontname ne "builtin") {
        $fontfile = lc($fontname);
        $fontfile .= ".ttf" if ($fontfile !~ /\.ttf$/);
        $fontfile = "/usr/local/fonts/$fontfile";
        @bounds = GD::Image->stringTTF(0,$fontfile,$fontsize,0,1,1,$text);
        if ($#bounds == 7) {
            $stringheight = $bounds[5] - $bounds[3];
            $stringwidth = $bounds[2] - $bounds[0];
            $x = int(($width - $stringwidth)/2);
            $y = int(($height - $stringheight)/2);
            $im->stringTTF(&color($fontcolor),$fontfile,$fontsize,0,$x,$y,$text);
        }
        else {
            $im->string(gdSmallFont,5,5,$@ . ": $fontfile",&color($fontcolor));
        }
    }
    else {
        $fontsize = $#builtin_font if ($fontsize > $#builtin_font);
        $font = $builtin_font[$fontsize];
        $fontheight = $font->height;
        $fontwidth = $font->width;
        $x = int(($width - $fontwidth*length($text))/2);
        $y = int(($height - $fontheight + 1)/2);
        $im->string($font,$x,$y,$text,&color($fontcolor));
    }
}
else {
    $im->rectangle(0,0,99,99,&color("black"));  # Put a black frame around the picture
    $im->arc(50,50,95,75,0,360,&color("blue")); # Draw a blue oval
    $im->fill(50,50,&color("red"));             # And fill it with red
}

binmode STDOUT;   # make sure we are writing to a binary stream

$method = $cgi->request_method();

if ($method) {
    #print $cgi->header(-type=>"image/$type");
    print $cgi->header(-type=>"image/$type", -expires=>'+1d', -Last_modified => 'Sun, 06 Jan 1980 00:00:00 GMT');
}

if ($method ne "HEAD") {
    if ($type eq "jpeg") {
        $quality = $cgi->param("quality");
        $quality = 100 if (!defined $quality || $quality !~ /^[0-9]+$/);
        $quality = 0 if ($quality < 0);
        $quality = 100 if ($quality > 100);
        print $im->jpeg($quality);
    }
    else {
        print $im->png;
    }
}



( run in 1.378 second using v1.01-cache-2.11-cpan-39bf76dae61 )