diff yaml_to_html.pl @ 6:0cf41189f086 draft

planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopore_qc commit 0d8d1ec70b450f96a29a98e4dec9688b18170d32
author jdv
date Sun, 12 Aug 2018 13:21:30 -0400
parents 192df6f6a41e
children
line wrap: on
line diff
--- a/yaml_to_html.pl	Mon Mar 12 19:55:54 2018 -0400
+++ b/yaml_to_html.pl	Sun Aug 12 13:21:30 2018 -0400
@@ -5,12 +5,13 @@
 use 5.012;
 
 use YAML::XS qw/LoadFile/;
+use MIME::Base64;
 use autodie;
 
-my ($fn_in, $fn_out) = @ARGV;
+my ($fn_yaml, $dir_in, $fn_out) = @ARGV;
 
 die "Can't find or read input file: $!\n"
-    if (! -r $fn_in);
+    if (! -r $fn_yaml);
 
 # set output filehandle based on arguments
 my $fh = \*STDOUT;
@@ -18,9 +19,9 @@
     open $fh, '>', $fn_out;
 }
 
-my $yaml = LoadFile($ARGV[0]);
+my $yaml = LoadFile($fn_yaml);
 
-convert($yaml);
+convert($yaml, $dir_in);
 
 sub convert {
 
@@ -99,16 +100,26 @@
 
 
     say {$fh} "    <h3>QC plots</h3>";
-    say {$fh} "    <p>(Click on plot for hi-resolution version)</p>";
+    say {$fh} "    <p>(Click on plot for high-resolution version, or in Chrome \"Open link in new tab\")</p>";
 
     for my $base (@order) {
 
         my $caption = $figs{$base} // die "No caption found for $base";
+     
+        # Base64-encode images
+        my $fn_img_full   = "$dir_in/$base.png";
+        my $fn_img_screen = "$dir_in/$base.screen.png";
+        die "Failed to find or read $fn_img_full"
+            if (! -r $fn_img_full);
+        die "Failed to find or read $fn_img_screen"
+            if (! -r $fn_img_screen);
+        my $img_full   = encode($fn_img_full);
+        my $img_screen = encode($fn_img_screen);
 
         print {$fh} <<"CONTENT"
-    <a href="$base.png">
+    <a href="data:image/png;base64,$img_full">
         <figure>
-            <img src="$base.screen.png" alt="$base" />
+            <img src="data:image/png;base64,$img_screen" alt="$base" />
             <figcaption>$caption</figcaption>
         </figure>
     </a>
@@ -120,7 +131,14 @@
 
 }
 
+sub encode {
 
+    my ($fn) = @_;
+    open my $in, '<:raw', $fn;
+    local($/) = undef;
+    return encode_base64(<$in>);
+
+}
 
 sub header {