Skip to content

Instantly share code, notes, and snippets.

@encadyma
Created February 23, 2015 02:33
Show Gist options
  • Save encadyma/79871f8084e93fe87bc2 to your computer and use it in GitHub Desktop.
Save encadyma/79871f8084e93fe87bc2 to your computer and use it in GitHub Desktop.
<html>
<head>
<title>Pictures</title>
<style>
body {
margin: 0;
padding: 0;
font-family: Roboto, sans-serif;
}
.photo {
display: inline-block;
-webkit-transform: scale(1);
-ms-transform: scale(1);
transform: scale(1);
-webkit-transition: all 500ms ease;
transition: all 500ms ease;
}
.photo:hover {
-webkit-transform: scale(1.2);
-ms-transform: scale(1.2);
transform: scale(1.2);
-webkit-transition: all 500ms ease;
transition: all 500ms ease;
}
</style>
</head>
<body>
<center>
<h1>I like pictures.</h1>
<?php
$max_width = 400;
$max_height = 400;
$dir = 'res/';
$imgs = array();
if (is_dir($dir)){
if ($d_handle = opendir($dir)){
while (($dir_entry = readdir($d_handle)) !== false){
//$files[] = $dir_entry;
$ext = pathinfo('res/'.$dir_entry)['extension'];
if ($ext == "jpg" || $ext == "jpeg" || $ext == "png" || $ext == "gif"){
$imgs[] = $dir_entry;
}
}
closedir($d_handle);
}
}
// var_export($imgs); echo "<br/><br/>";
foreach($imgs as $img){
$img_info = getimagesize("res/".$img);
$img_info['width'] = $img_info[0];
$img_info['height'] = $img_info[1];
$img_info['scale'] = sqrt(($img_info['width'] * $img_info['height'])/($max_width * $max_height));
$img_info['width'] = ($img_info['width']/$img_info['scale']);
$img_info['height'] = ($img_info['height']/$img_info['scale']);
echo "<a href='res/".$img."' target='_tab' style='display:inline-block;'><div class='photo'><img src='res/".$img."' alt='Image.' width='".$img_info['width']."' height='".$img_info['height']."'/></div></a>";
}
?>
</center>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment