...

View Full Version : gallery script problem



Baby
02-27-2007, 10:49 PM
I'm using the "Gallery Thingie" script to run a simple gallery. The idmin area lets you reorder the images by changing the "id" number. I get a confirmation message "Thumbnail updated. Thumbnail deleted. Image edited." Everything is reordered, and the thumbnail is deleted, but the thumbnail is not recreated. If you go back and click "update thumbnail" again, the thumb IS recreated. How can I get a new thumb created when the id is changed? ($newid)

I don't know anything at all about php, so if you can help, please explain the obvious. Thanks!

Here are the snippets that seem relevant:



// EDIT IMAGE

function editImage($oldid, $newid, $newtitle, $newdescription, $newcat, $filename = "", $updatethumb = "") {
global $name, $title, $description, $cat, $enableThumbnails, $thumbnailwidth, $thumbnailquality, $path;
$newdescription = stripslashes(trim($newdescription));
$newtitle = stripslashes(trim($newtitle));
if ($enableThumbnails == TRUE && $updatethumb != "") {
// Delete old thumbnail file.
if (!file_exists("{$path}thumbs/{$filename}") || @unlink("{$path}thumbs/{$filename}")) {
// Create thumbnail.
$msg = createThumbnail($filename, $thumbnailwidth, $thumbnailquality);
if ($msg == 0) {
echo "<p class=\"ok\">Thumbnail updated.</p>";
} else {
echo "<p class=\"alarm\">{$msg}</p>";
}
} else {
echo "<p class=\"alarm\">Old thumbnail file could not be deleted.</p>";
}
}
if ($oldid == $newid) {
$title[$newid] = $newtitle;
$description[$newid] = $newdescription;
$cat[$newid] = $newcat;
if (saveFile() == TRUE) {
echo "<p class=\"ok\">Image edited.</p>";
return TRUE;
} else {
echo "<p class=\"alarm\">Could not update data file.</p>";
return FALSE;
}
} else {
$newname = $name[$oldid];
if (!IsSet($name[$newid])) {
if (deleteImage($oldid, "no", "no") == TRUE) {
$name[] = $newname;
$title[] = $newtitle;
$description[] = $newdescription;
$cat[] = $newcat;
if (saveFile() == TRUE) {
echo "<p class=\"ok\">Image edited.</p>";
return TRUE;
} else {
echo "<p class=\"alarm\">Could not update data file.</p>";
return FALSE;
}
} else {
echo "<p class=\"alarm\">Could not remove old ID.</p>";
return FALSE;
}
} else {
if (deleteImage($oldid, "no", "no") == TRUE) {
$temp = array_splice($name, $newid);
$name[] = $newname;
foreach ($temp as $value) {
$name[] = $value;
}
UnSet($temp);
$temp = array_splice($title, $newid);
$title[] = $newtitle;
foreach ($temp as $value) {
$title[] = $value;
}
UnSet($temp);
$temp = array_splice($description, $newid);
$description[] = $newdescription;
foreach ($temp as $value) {
$description[] = none;
}
UnSet($temp);
$temp = array_splice($cat, $newid);
$cat[] = $newcat;
foreach ($temp as $value) {
$cat[] = $value;
}
UnSet($temp);
if (saveFile() == TRUE) {
echo "<p class=\"ok\">Image edited.</p>";
return TRUE;
} else {
echo "<p class=\"alarm\">Could not update data file.</p>";
return FALSE;
}
} else {
echo "<p class=\"alarm\">Could not remove old ID.</p>";
return FALSE;
}
}
}
}


// CREATE THUMBNAIL

function createThumbnail($orgimg, $thumbnailwidth, $thumbnailquality) {
global $path;
$thumbpath = "{$path}thumbs/{$orgimg}";
$orgimg = "{$path}{$orgimg}";
$error = 0;
if (function_exists('imagecreate') && function_exists('imagecopyresized')) {
// Check if thumbnail directory exists. If not try to create it.
if (!is_dir("{$path}thumbs")) {
$oldumask = umask(0);
if (@!mkdir("{$path}thumbs", 0777)) {
$error = "Thumbnail directory could not be created.";
}
umask($oldumask);
}
// Get file size and file type.
if ($error == 0) {
if (!$size = @getimagesize($orgimg)) {
$error = "Size of original image could not be calculated.";
}
}
// Create link to old image.
if ($error == 0) {
switch ($size[2]) {
case 1 :
if (function_exists('imagecreatefromgif')) {
$img = @imagecreatefromgif($orgimg);
if ($img == "") {
$error = "Could not open link to original image.";
}
} else {
$error = "Could not open link to original image.";
}
break;
case 2 :
if (function_exists('imagecreatefromjpeg')) {
$img = @imagecreatefromjpeg($orgimg);
if ($img == "") {
$error = "Could not open link to original image.";
}
} else {
$error = "Could not open link to original image.";
}
break;
case 3 :
if (function_exists('imagecreatefrompng')) {
$img = @imagecreatefrompng($orgimg);
if ($img == "") {
$error = "Could not open link to original image.";
}
} else {
$error = "Could not open link to original image.";
}
break;
default :
$error = "Cannot create thumbnail. Original image is of an unsupported type.";
break;
}
}
// Calculate the dimensions of the new image.
if ($error == 0) {
if (!strstr($thumbnailwidth, "%")) {
if($size[0] > $size[1]) {
$ratio = $size[0]/$thumbnailwidth;
$height = $size[1]/$ratio;
$height = round($height);
$width = $size[0]/$ratio;
} else {
$ratio = $size[1]/$thumbnailwidth;
$width = $size[0]/$ratio;
$width = round($width);
$height = $size[1]/$ratio;
}
} else {
$ratio = str_replace("%", "", $thumbnailwidth)/100;
$width = round($size[0]*$ratio);
$height = round($size[1]*$ratio);
}
}
// Create new image (true colour if available).
if ($error == 0) {
if (function_exists('imagecreatetruecolor')) {
$newimg = imagecreatetruecolor($width, $height);
} else {
$newimg = imagecreate($width, $height);
}
}
// Resample old image over new image.
if ($error == 0) {
if(!function_exists('imagecopyresampled') || !function_exists('imagecreatetruecolor')) {
if (!@imagecopyresized($newimg, $img, 0, 0, 0, 0, $width, $height, $size[0], $size[1])) {
$error = "Could not resize image.";
}
} else {
if (!@imagecopyresampled($newimg, $img, 0, 0, 0, 0, $width, $height, $size[0], $size[1])) {
$error = "Could not resample image.";
}
}
}
// Make the thumbnails, and save files.
if ($error == 0) {
switch ($size[2]) {
case 1:
if (!@imagegif($newimg, $thumbpath)) {
$error = "Could not save thumbnail.";
}
break;
case 2:
if (!@imagejpeg($newimg, $thumbpath, $thumbnailquality)) {
$error = "Could not save thumbnail.";
}
break;
case 3:
if (!@imagepng($newimg, $thumbpath)) {
$error = "Could not save thumbnail.";
}
break;
default :
$error = "Could not create thumbnail. Image type not supported.";
}
}
// Destroy image both links.
@imagedestroy($newimg);
@imagedestroy($img);
} else {
$error = "Image functions not available for thumbnail.";
}
return $error;
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum