How can one automate the thumbnail creation process in Simple Picture Gallery Manager?
To automate the thumbnail creation process in Simple Picture Gallery Manager, you can use PHP's GD library to generate thumbnails for each image uploaded to the gallery. This can be achieved by writing a script that loops through the images in the gallery directory, creates a thumbnail for each image, and saves it in a separate directory.
<?php
$galleryPath = 'path/to/gallery/';
$thumbPath = 'path/to/thumbnails/';
$images = glob($galleryPath . '*.{jpg,jpeg,png,gif}', GLOB_BRACE);
foreach ($images as $image) {
$imgInfo = getimagesize($image);
$imgType = $imgInfo[2];
switch ($imgType) {
case IMAGETYPE_JPEG:
$sourceImg = imagecreatefromjpeg($image);
break;
case IMAGETYPE_PNG:
$sourceImg = imagecreatefrompng($image);
break;
case IMAGETYPE_GIF:
$sourceImg = imagecreatefromgif($image);
break;
}
$thumbWidth = 150;
$thumbHeight = 150;
$thumb = imagecreatetruecolor($thumbWidth, $thumbHeight);
imagecopyresized($thumb, $sourceImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, imagesx($sourceImg), imagesy($sourceImg));
$thumbName = $thumbPath . basename($image);
switch ($imgType) {
case IMAGETYPE_JPEG:
imagejpeg($thumb, $thumbName);
break;
case IMAGETYPE_PNG:
imagepng($thumb, $thumbName);
break;
case IMAGETYPE_GIF:
imagegif($thumb, $thumbName);
break;
}
imagedestroy($sourceImg);
imagedestroy($thumb);
}
?>