use strict;use warnings;use Image::Magick;my ($my_styles);$my_styles = {style1 => {font => "Arial",color => "#000000",size => "20"},style2 => {font => "Arial",color => "#00ff00",size => "25"}};#returns the image magick object after rendering the text, with given height andwidth.#it truncates the paragraph after reaching the height limit.#wraps the text, and also can support multiple styles in the same linesub draw_styled_text {my ($text, $height, $width, $default_style) = @_;my $im = Image::Magick->new();my $last_pos = 0;my ($x, $y) = (0, 0);my %lines;$im->Set(size => $width . "x" . $height);$im->Read('xc:none');#format#sentence%%$$style_name$$sentence%%sentence#for each styled sentencemy @sentences = split /\%\%/, $text;for my $sentence (@sentences) {my ($style_name, $style_details);$style_name = $default_style;if ($sentence =~ /\$\$(.*)\$\$([\w\W]*)/) {#get the style name,$style_name = $1;$sentence = $2;}#check length of the stringunless (length $sentence) {next;}#get the style details,$style_details = get_style_details($style_name);$im->Set(font => $style_details->{'font'},pointsize => $style_details->{'pointsize'});#wrap text
Add a Comment
jackdewitleft a comment