Text on Transparent background image breaks
Posted: 2013-11-10T23:30:48-07:00
I would like to add a Text with given font, size to an image that has transparent background.
The code is as follows
Method#1:
my $im = Image::Magick->new(magick => 'png');
$im->Set( size => "$options{image_length} x $options{image_width}" );
$im->ReadImage( "xc:none" );
$im->Annotate( fill => $options{text_color},
pointsize => $options{text_size},
x => $x_pos,
text => $text,
y => $y_pos,
font => $options{text_font} );
Method#2:
my $im = Image::Magick->new(magick => 'png');
$im->Set( size => "$options{image_length} x $options{image_width}" );
$im->ReadImage( "xc:#FFFFFF" );
$im->Transparent(color=>'#FFFFFF');
$im->Annotate( fill => $options{text_color},
pointsize => $options{text_size},
x => $x_pos,
text => $text,
y => $y_pos,
font => $options{text_font} );
I'm creating an image with white background, and making it transparent, and then writing text in black color.
However when I make the background transparent, the text gets distorted - font breaks.
I see that with above 2 options, the font of the text gets changed - and if font size is very small, I see blurred/overlapped text. If the background is not made transarent, the text looks fine.
The requirement is: Need to create an image with transparent background and annotate the same.
Please suggest.
The code is as follows
Method#1:
my $im = Image::Magick->new(magick => 'png');
$im->Set( size => "$options{image_length} x $options{image_width}" );
$im->ReadImage( "xc:none" );
$im->Annotate( fill => $options{text_color},
pointsize => $options{text_size},
x => $x_pos,
text => $text,
y => $y_pos,
font => $options{text_font} );
Method#2:
my $im = Image::Magick->new(magick => 'png');
$im->Set( size => "$options{image_length} x $options{image_width}" );
$im->ReadImage( "xc:#FFFFFF" );
$im->Transparent(color=>'#FFFFFF');
$im->Annotate( fill => $options{text_color},
pointsize => $options{text_size},
x => $x_pos,
text => $text,
y => $y_pos,
font => $options{text_font} );
I'm creating an image with white background, and making it transparent, and then writing text in black color.
However when I make the background transparent, the text gets distorted - font breaks.
I see that with above 2 options, the font of the text gets changed - and if font size is very small, I see blurred/overlapped text. If the background is not made transarent, the text looks fine.
The requirement is: Need to create an image with transparent background and annotate the same.
Please suggest.