Skip to content

Instantly share code, notes, and snippets.

@SciutoAlex
Created October 8, 2013 17:38
Show Gist options
  • Select an option

  • Save SciutoAlex/6888447 to your computer and use it in GitHub Desktop.

Select an option

Save SciutoAlex/6888447 to your computer and use it in GitHub Desktop.
Add this page to any folder, and it'll pull the latest modified image and add it as a CSS background image. Great for quickly previewing web designs. Also great for sharing designs that clients can see right in the browser. Automatically centers the image, but you could tweak the CSS for align-left or align-right webpages.
<?php
$path = ".";
$latest_ctime = 0;
$latest_filename = '';
$d = dir($path);
while (false !== ($entry = $d->read())) {
$filepath = "{$path}/{$entry}";
//echo filectime($filepath)." ".$entry."<br>";
if (getimagesize($filepath) && filectime($filepath) > $latest_ctime) {
$latest_ctime = filectime($filepath);
$latest_filename = $entry;
$imagepath = "{$path}/{$entry}";
$urlpath = $entry;
$date = date("F d Y", filectime($filepath));
}
}
list($w, $h, $size, $attr) = getimagesize($imagepath);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
<meta name="viewport" content="width=<?= $w ?>, user-scalable=false, initial-scale=.5, maximum-scale=.5, minimum-scale=.5;">
<style>
body {
margin:0px;
padding:0px;
font-family:arial;
font-size:0px;
font-weight:bold;
text-align:center;
font-size:12px;
}
.body {
width:100%;
margin:000px auto;
background: url('<?= htmlentities($urlpath) ?>') center top no-repeat;
height: <?= $h ?>px;
}
.top {
padding:10px;
height: 30px;
color:white;
background:red;
font-size:14px;
text-align:left;
}
p {
display:inline-block;
}
</style>
</head>
<body>
<div class="body"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment