AAC-Pvoice
view release on metacpan or search on metacpan
lib/AAC/Pvoice/Bitmap.pm view on Meta::CPAN
{
my $pt = 20;
do {
(undef, undef, undef, undef, $textwidth, $textheight, undef) =
$background->QueryFontMetrics(text => $caption, font => 'Comic-Sans-MS', pointsize => $pt, gravity => 'South');
$pt--;
} until ($textwidth < $x) && ($textheight < $y/5);
$background->Annotate(text => $caption, font => 'Comic-Sans-MS', pointsize => $pt, gravity => 'South');
}
# Read the actual image
my $img = Image::Magick->new;
my $rc = $img->Read($file);
carp "Can't read $file: $rc" if $rc;
# wmf files have a white background color by default
# if we can't get the matte color for the image, we assume
# that white can be used as the transparent color...
$img->Transparent(color => 'white') if (!$img->Get('matte') || $file =~ /wmf$/i);
my $w = $img->Get('width');
my $h = $img->Get('height');
my $ch = $textheight;
if (($w > $x) || ($h > ($y-$ch)))
{
my ($newx, $newy) = ($w, $h);
if ($w > $x)
{
my $factor = $w/$x;
return wxNullBitmap if not $factor;
$newy = int($h/$factor);
($w,$h) = ($x, $newy);
}
if ($h > ($y-$ch))
{
my $factor = $h/($y-$ch);
return wxNullBitmap if not $factor;
($w, $h) = (int($w/$factor),$y-$ch);
}
$img->Thumbnail(height => $h, width =>$w );
}
elsif ($blowup)
{
# Do we really want to blow up images that are too small??
my $factor = $w/$x;
return wxNullBitmap if not $factor;
my $newy = int($h/$factor);
($w,$h) = ($x, $newy);
if ($h > ($y-$ch))
{
my $factor = $h/($y-$ch);
return wxNullBitmap if not $factor;
($w, $h) = (int($w/$factor),$y-$ch);
}
$img->Resize(height => $h, width =>$w );
}
$img->Border(width => int(($x - $img->Get('width'))/2) - $radius/2,
height => int((($y-$textheight) - $img->Get('height'))/2) - $radius/2,
fill => $ibg);
# Call the Composite method of the background image, with the logo image as an argument.
$background->Composite(image=>$img,compose=>'over', gravity => 'North');
$background->Set(quality=>100);
$background->Set(magick => 'png');
$image = $background->imagetoblob();
$cache->set("$file-$x-$y-$caption-$ibg-$blowup-$pbg-$mtime", $image);
undef $background;
undef $img;
}
my $fh = IO::Scalar->new(\$image);
my $contenttype = 'image/png';
return Wx::Bitmap->new(Wx::Image->newStreamMIME($fh, $contenttype))
}
END
{
undef $cache;
}
sub DrawCaption
{
my ($x, $y, $caption, $background, $parent_background) = @_;
confess "MaxX and MaxY should be positive" if $x < 1 || $y < 1;
my $newbmp = Wx::Bitmap->new($x, $y);
my $tmpdc = Wx::MemoryDC->new();
$tmpdc->SelectObject($newbmp);
my $bgbr = Wx::Brush->new($parent_background, wxSOLID);
$tmpdc->SetBrush($bgbr);
$tmpdc->SetBackground($bgbr);
$tmpdc->Clear();
my $bg = $parent_background;
if (defined $background)
{
if (ref($background)=~/ARRAY/)
{
$bg = Wx::Colour->new(@$background);
}
else
{
$bg = $background;
}
my $br = Wx::Brush->new($bg, wxSOLID);
my $pen = Wx::Pen->new($bg, 1, wxSOLID);
$tmpdc->SetBrush($br);
$tmpdc->SetPen($pen);
$tmpdc->DrawRoundedRectangle(1,1,$x-1,$y-1, 10);
}
my $pt = 72;
my ($font, $w, $h);
do
{
$font = Wx::Font->new( $pt, # font size
wxSWISS, # font family
wxNORMAL, # style
( run in 0.927 second using v1.01-cache-2.11-cpan-5735350b133 )