我最近用PHP首次构建了一个网站。我已经创建了一个使用各种教程的画廊脚本,它可以自动拉取设置位置中的图像,并创建一个缩略图(如果不退出)。PHP Image Resize(gallery)
现在我上传的正常工作一样通过图像拉动,但是脚本出于某种原因,不会重新大小的图像!这真的开始困扰我了,因为我以前从未使用过PHP,所以我完全失败。我的脚本,它下面
<?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>';
}
}
?>
我认为错误的东西与我的路径,但我不知道,任何人都可以提供一些线索这光????
对不起,是愚蠢的,但我真的这个迷惑(我是一个总的新手!)。我在自己的代码中错过了什么吗? – Callum 2013-03-14 13:18:37
如果问题是关于路径比你应该给图像文件夹的绝对路径可能这会帮助你。 – ajay 2013-03-14 13:23:31
像绝对路径 - D:/xampplite/htdocs/image/image.jpg – ajay 2013-03-14 13:25:20