More pretty previews.
This commit is contained in:
parent
43f7130901
commit
cbce2c9249
@ -21,7 +21,7 @@ const my $OWLCODE_LOGO => $PUBLIC_DIR->child('img/owlcode_tech.webp');
|
|||||||
const my $SVG_WIDTH => 1200;
|
const my $SVG_WIDTH => 1200;
|
||||||
const my $SVG_HEIGHT => 627;
|
const my $SVG_HEIGHT => 627;
|
||||||
const my $SVG_EMBEDDED_IMAGE_MAX_WIDTH => 1000;
|
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 ) {
|
sub Generate ( $self, $title, $content, $image_file, $site_name ) {
|
||||||
my $dom = Mojo::DOM->new($content);
|
my $dom = Mojo::DOM->new($content);
|
||||||
@ -171,6 +171,7 @@ sub _AttachImageSVG ( $self, $svg, $image_file ) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
my ( $width, $height ) = $stdout =~ /^"(\d+)x(\d+)"$/;
|
my ( $width, $height ) = $stdout =~ /^"(\d+)x(\d+)"$/;
|
||||||
|
my $height_complete_image = (1200 / $width) * $height;
|
||||||
if ( $height > $SVG_EMBEDDED_IMAGE_MAX_HEIGHT ) {
|
if ( $height > $SVG_EMBEDDED_IMAGE_MAX_HEIGHT ) {
|
||||||
$width /= $height / $SVG_EMBEDDED_IMAGE_MAX_HEIGHT;
|
$width /= $height / $SVG_EMBEDDED_IMAGE_MAX_HEIGHT;
|
||||||
$width = int($width);
|
$width = int($width);
|
||||||
@ -184,18 +185,25 @@ sub _AttachImageSVG ( $self, $svg, $image_file ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
my $x = int( ( $SVG_WIDTH / 2 ) - ( $width / 2 ) );
|
my $x = int( ( $SVG_WIDTH / 2 ) - ( $width / 2 ) );
|
||||||
my $y = 90;
|
my $y = 50;
|
||||||
my ($output) = capture {
|
my ($output) = capture {
|
||||||
system qw/file --mime-type/, $image_file;
|
system qw/file --mime-type/, $image_file;
|
||||||
};
|
};
|
||||||
my ($format) = $output =~ /(\S+)$/;
|
my ($format) = $output =~ /(\S+)$/;
|
||||||
$svg->image(
|
$svg->image(
|
||||||
x => $x,
|
x => 0,
|
||||||
y => $y,
|
y => $y,
|
||||||
width => $width,
|
width => $SVG_WIDTH,
|
||||||
height => $height,
|
height => $height_complete_image,
|
||||||
-href => "data:$format;base64," . encode_base64( $image_file->slurp )
|
-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;
|
return $y + $height + 50;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user