Skip to content

Instantly share code, notes, and snippets.

@amadornes
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amadornes/34269372405a881e36b7 to your computer and use it in GitHub Desktop.
Save amadornes/34269372405a881e36b7 to your computer and use it in GitHub Desktop.
Screenshot wrapper
Options -Indexes
RewriteEngine On
RewriteRule ^([A-Za-z0-9-]+)/?$ wrap.php?img=$1 [NC,L]
<?php
function endsWith($haystack, $needle){
return strrpos($haystack, $needle) + strlen($needle) ===
strlen($haystack);
}
$img = $_GET['img'];
$path = $img . ".jpg";
foreach (glob($img . ".*") as $filename) {
$path = $filename;
break;
}
$code = "There was an error when trying to load the screenshot.";
$type = "Error";
if(endsWith($path, ".jpg") || endsWith($path, ".png")){
$type = "img";
$code = "<img id=\"content\" src=\"$path\">";
}elseif(endsWith($path, ".mp4")){
$type = "vid";
$code = "<video id=\"content\" controls=\"\" autoplay=\"\" name=\"media\"><source src=\"$path\" type=\"video/mp4\"></video>";
}
?>
<html>
<head>
<title>Screenshot</title>
<style>
* {
margin:0;
padding:0;
}
body {
background-color: #383838;
}
#content {
position: absolute;
max-width: 75%;
max-height: 75%;
margin: auto;
left: 0;
right: 0;
top: 0;
bottom: 0;
-webkit-box-shadow: 0px 2px 27px 2px rgba(0,0,0,0.8);
-moz-box-shadow: 0px 2px 27px 2px rgba(0,0,0,0.8);
box-shadow: 0px 2px 27px 2px rgba(0,0,0,0.8);
}
</style>
<?php if($type == "img"){ ?>
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="@amadornes">
<meta name="twitter:creator" content="@amadornes">
<meta name="twitter:title" content="Screenshot">
<meta name="twitter:description" content="Screenshot!">
<meta name="twitter:image" content="http://ss.amadornes.com/<?php echo $path; ?>">
<?php } ?>
</head>
<body>
<a href="<?php echo $path; ?>" title="Click to view in full size">
<?php echo $code; ?>
</a>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment