Created
July 13, 2017 15:06
-
-
Save bdunnette/f0391e8107895170ff28ff77c04169e0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # This script requires libvips-tools to be installed | |
| trackingcode="UA-39453866-3" | |
| imagehost="web-basic.oit.umn.edu" | |
| tracking_script="<script>(function(e,t,n,r,i,s,o){e[\"GoogleAnalyticsObject\"]=i;e[i]=e[i]||function(){(e[i].q=e[i].q||[]).push(arguments)},e[i].l=1*new Date;s=t.createElement(n),o=t.getElementsByTagName(n)[0];s.async=1;s.src=r;o.parentNode.insertBefore(s,o)})(window,document,\"script\",\"//www.google-analytics.com/analytics.js\",\"ga\");ga(\"create\",\"$trackingcode\",\"umn.edu\");ga(\"send\",\"pageview\")</script>" | |
| indextitle=${PWD##*/} | |
| year=`date +%Y` | |
| institution="Regents of the University of Minnesota" | |
| copyright="© $year $institution" | |
| #Write header to index.html, using first command-line argument as title (if given) | |
| pagehead="<!DOCTYPE html><html><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><title>$indextitle</title><link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css\"/></head><body><div class=\"container\"><div class=\"page-header\"><h2>$indextitle</h2></div><div class=\"row list-group\">" | |
| echo $pagehead > index.html | |
| index=0 | |
| for s in *.svs | |
| do | |
| i="${s%.*}" | |
| slidetitle="$i" | |
| pagefile="$i.html" | |
| vips openslideload --associated thumbnail $s $i.jpg && vipsthumbnail $i.jpg | |
| tn_width=`vipsheader -f width tn_$i.jpg` | |
| tn_height=`vipsheader -f height tn_$i.jpg` | |
| micronsperpixel=`vipsheader -f openslide.mpp-x $s` | |
| echo "<a class=\"list-group-item\" href=\"$pagefile\"><img src=\"tn_$i.jpg\" class=\"img-thumbnail\" height=\"$tn_height\" width=\"$tn_width\"> <strong>$slidetitle</strong></a>" >> index.html | |
| page_head="<!DOCTYPE html><html><head><meta charset=\"utf-8\"><title>$indextitle: $slidetitle</title><meta name=\"viewport\" content=\"width=device-width\"><script src=\"//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js\"></script><script src=\"//cdnjs.cloudflare.com/ajax/libs/openseadragon/2.2.1/openseadragon.min.js\"></script><script src=\"//pages.nist.gov/OpenSeadragonScalebar/openseadragon/openseadragon-scalebar.js\"></script>" | |
| page_body="</head> | |
| <body style=\"margin:0;\"> | |
| <div id=\"contentDiv\" class=\"openseadragon\" style=\"height:800px;width:100%;\"></div> | |
| <script type=\"text/javascript\"> | |
| \$(document).ready(function() { | |
| \$('#contentDiv').css({ | |
| height: \$(window).height() + 'px' | |
| }); | |
| var viewer = new OpenSeadragon.Viewer({ | |
| id: \"contentDiv\", | |
| prefixUrl: \"//cdnjs.cloudflare.com/ajax/libs/openseadragon/2.2.1/images/\", | |
| tileSources: \"$i.dzi\", | |
| showNavigator: true, | |
| navigatorAutoFade: 3, | |
| crossOriginPolicy: \"Anonymous\" | |
| }); | |
| viewer.scalebar({ | |
| type: \"microscopy\", | |
| pixelsPerMeter: 1e6 * (1/$micronsperpixel), | |
| stayInsideImage: true, | |
| backgroundColor: \"rgba(255, 255, 255, 0.5)\" | |
| }); | |
| \$(window).resize(function() { | |
| \$('#contentDiv').css({ | |
| height: \$(window).height() + 'px' | |
| }); | |
| }); | |
| }); | |
| </script>" | |
| page_foot="</body></html>" | |
| echo "Writing $pagefile..." | |
| echo "$page_head $js_and_css $page_body $tracking_script $page_foot" > $pagefile | |
| ((index++)) | |
| done | |
| #Finish writing index.html and upload to server | |
| echo "Writing index.html..." | |
| echo "</div><div class=\"row\"><h4>$copyright</h4></div>$tracking_script</body></html>" >> index.html | |
| #Process SVS files | |
| index=0 | |
| for s in *.svs | |
| do | |
| i="${s%.*}" | |
| echo "Processing $s" | |
| imagedir_suffix='_files' | |
| imagedir=$i$imagedir_suffix | |
| #Remove existing image directory if it exists | |
| if [ -d $imagedir ] | |
| then | |
| rm -R $imagedir | |
| fi | |
| time /usr/bin/vips dzsave $s $i.dzi | |
| #zip $i $pagefile | |
| ((index++)) | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment