Skip to content

Instantly share code, notes, and snippets.

@vicgonvt
Created March 15, 2017 01:49
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 vicgonvt/c3ede6e84e0732abc168ec79881befb7 to your computer and use it in GitHub Desktop.
Save vicgonvt/c3ede6e84e0732abc168ec79881befb7 to your computer and use it in GitHub Desktop.
<?php
class Gallery
{
public $data;
public function setUp($imagePath)
{
$data = file_get_contents($imagePath . 'portfolio.json');
$this->data = json_decode($data, true);
$this->images = glob($imagePath . '*.{jpg,png,gif}', GLOB_BRACE);
}
}
class Image extends Gallery
{
public function __construct($imagePath)
{
$this->setUp();
$file = pathinfo($imagePath, PATHINFO_FILENAME);
$extension = pathinfo($imagePath, PATHINFO_EXTENSION);
$this->image = $file;
$this->thumb = $file . '-thumb' . $extension;
if (array_key_exists($this->image, $this->data)) {
$this->title = $this->data[$file]['title'];
$this->description = $this->data[$file]['description'];
}
}
}
$gallery = new Gallery(__DIR__ . '/portfolio/');
?>
<!DOCTYPE html>
<html>
<head>
<title>Jani Gyllenberg | Marketing &amp; Web Development</title>
</head>
<body>
<?php
foreach ($gallery->images as $image) {
$image = new Image($image);
echo $image->image;
echo $image->title;
}
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment