More pretty previews.

This commit is contained in:
sergiotarxz 2023-05-17 05:55:03 +02:00
parent 43f7130901
commit cbce2c9249

View File

@ -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;
}