I've recently built a website using PHP for the first time. I have create a gallery script using various tutorials which automatically pulls through images held in a set location and creates a thumbnail, if one does not exit.
Now my upload works fine as does pulling through the images, however the script for some reason, will not re-size the image! This is really beginning to baffle me now and as I have never used php before, I am at a total loss. My script it below
<?php
# SETTINGS
$max_width = 100;
$max_height = 100;
function getPictureType($ext) {
if ( preg_match('/jpg|jpeg/i', $ext) ) {
return 'jpg';
} else if ( preg_match('/png/i', $ext) ) {
return 'png';
} else if ( preg_match('/gif/i', $ext) ) {
return 'gif';
} else {
return '';
}
}
function getPictures() {
global $max_width, $max_height;
if ( $handle = opendir("Design/Images/Gallery/") ) {
$lightbox = rand();
echo '<div id="gallery"><ul>';
while ( ($file = readdir($handle)) !== false ) {
if ( !is_dir($file) ) {
$split = explode('.', $file);
$ext = $split[count($split) - 1];
if ( ($type = getPictureType($ext)) == '' ) {
continue;
}
if ( ! is_dir('Design/Images/Gallery/thumbs') ) {
mkdir('Design/Images/Gallery/thumbs');
}
if ( ! file_exists('Design/Images/Gallery/thumbs/'.$file) ) {
if ( $type == 'jpg' ) {
$src = imagecreatefromjpeg($file);
} else if ( $type == 'png' ) {
$src = imagecreatefrompng($file);
} else if ( $type == 'gif' ) {
$src = imagecreatefromgif($file);
}
if ( ($oldW = imagesx($src)) < ($oldH = imagesy($src)) ) {
$newW = $oldW * ($max_width / $oldH);
$newH = $max_height;
} else {
$newW = $max_width;
$newH = $oldH * ($max_height / $oldW);
}
$new = imagecreatetruecolor($newW, $newH);
imagecopyresampled($new, $src, 0, 0, 0, 0, $newW, $newH, $oldW, $oldH);
if ( $type == 'jpg' ) {
imagejpeg($new, 'Design/Images/Gallery/thumbs/'.$file);
} else if ( $type == 'png' ) {
imagepng($new, 'Design/Images/Gallery/thumbs/'.$file);
} else if ( $type == 'gif' ) {
imagegif($new, 'Design/Images/Gallery/thumbs/'.$file);
}
imagedestroy($new);
imagedestroy($src);
}
echo '<li><a href="Design/Images/Gallery/'.$file.'" rel="lightbox['.$lightbox.']">';
echo '<img src="Design/Images/Gallery/thumbs/'.$file.'" alt="" />';
echo '</a></li>';
}
}
echo '</ul></div>';
}
}
?>
I believe the error is something to do with my paths but I am not sure, can anyone shed some light on this????