From cbce2c9249e982ea2791033a161e9ec819da28c7 Mon Sep 17 00:00:00 2001 From: sergiotarxz Date: Wed, 17 May 2023 05:55:03 +0200 Subject: [PATCH] More pretty previews. --- lib/OwlcodeTech/Preview.pm | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/OwlcodeTech/Preview.pm b/lib/OwlcodeTech/Preview.pm index c12350c..28c1e02 100644 --- a/lib/OwlcodeTech/Preview.pm +++ b/lib/OwlcodeTech/Preview.pm @@ -21,7 +21,7 @@ const my $OWLCODE_LOGO => $PUBLIC_DIR->child('img/owlcode_tech.webp'); const my $SVG_WIDTH => 1200; const my $SVG_HEIGHT => 627; const my $SVG_EMBEDDED_IMAGE_MAX_WIDTH => 1000; -const my $SVG_EMBEDDED_IMAGE_MAX_HEIGHT => 200; +const my $SVG_EMBEDDED_IMAGE_MAX_HEIGHT => 400; sub Generate ( $self, $title, $content, $image_file, $site_name ) { my $dom = Mojo::DOM->new($content); @@ -171,6 +171,7 @@ sub _AttachImageSVG ( $self, $svg, $image_file ) { return; } my ( $width, $height ) = $stdout =~ /^"(\d+)x(\d+)"$/; + my $height_complete_image = (1200 / $width) * $height; if ( $height > $SVG_EMBEDDED_IMAGE_MAX_HEIGHT ) { $width /= $height / $SVG_EMBEDDED_IMAGE_MAX_HEIGHT; $width = int($width); @@ -184,18 +185,25 @@ sub _AttachImageSVG ( $self, $svg, $image_file ) { } my $x = int( ( $SVG_WIDTH / 2 ) - ( $width / 2 ) ); - my $y = 90; + my $y = 50; my ($output) = capture { system qw/file --mime-type/, $image_file; }; my ($format) = $output =~ /(\S+)$/; $svg->image( - x => $x, + x => 0, y => $y, - width => $width, - height => $height, + width => $SVG_WIDTH, + height => $height_complete_image, -href => "data:$format;base64," . encode_base64( $image_file->slurp ) ); + $svg->rect( + x => 0, + y => $y+$height, + width => $SVG_WIDTH, + height => $SVG_HEIGHT, + style => { fill => 'ghostwhite' }, + ); return $y + $height + 50; }