So I'm working on an image gallery and I have it set up as follows.
I have a generic Image object which knows the height, width, orientation, mime-type, etc. of a photo. The object is given a directory linking to the photo as well as things like the title, author, and an array of EXIF info.
I thought about how I wanted to handle thumbnails and it seemed like creating two strategy objects that implement the same ImageStyle interface would be a good way. Each Image object has two methods, makeThumb() and makeFull() which are each passed an instance of any ImageStyle object which are in turn given the instance of the Image object to which it was passed. This way, should the actual means of creating a thumbnail or full view of the photos in the gallery ever change, all I need to do is swap out those strategy objects and the rest of the module will remain in tact and functional.
However, I've stumbled upon a strange conundrum. In order to make the thumbs appear I did this:
Code: Select all
<?php
while($row = mysqli_fetch_assoc($rs)) {
$file = $row['fileName'];
$dir = './galleries/' . strtolower($row['category']) . '/';
$dir .= $file;
$title = $row['title'];
$author = $row['author'];
echo "<img src=\"getThumb.php?file=./$dir&title=$title
&author=$author\" id=\"thumbnail\" />";
}
?>Code: Select all
<?php
require_once 'Image.php';
require_once 'SquareCropThumb.php';
$file = $_GET['file'];
$title = $_GET['title'];
$author = $_GET['author'];
$img = new Image($file, $title, $author);
$mime = $img->getMime();
$img->makeThumb(new SquareCropThumb());
$thumb = $img->getThumb();
switch($mime) {
case 'image/jpeg':
header('Content-Type: image/jpeg');
imagejpeg($thumb, NULL, 80);
break;
case 'image/gif':
header('Content-Type: image/gif');
imagegif($thumb);
break;
case 'image/png':
header('Content-Type: image/png');
imagepng($thumb);
break;
default:
echo 'File is not an image';
break;
}
?>Am I going about this all wrong, or is my solution not as bad as I think it might be?
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: