Created
March 15, 2017 01:49
-
-
Save vicgonvt/c3ede6e84e0732abc168ec79881befb7 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
<?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 & 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