Hi!
I love ZenPhoto, it's nice and lightweight. I've set up a few websites for people and for the image gallery I am using ZenPhoto, the problem I have had is that I don't want them uploading full size images and using up their webspace.
So I developed a small little hack, which I thought might be useful.
in admin.php on line 118 right after
@chmod($uploadfile, 0777);
I added these few lines of code. The result is that any images that are uploaded are scalled to 800 px along the largest size. This is a big save for webspace.
// Image Scaling Hack!!
list($width_orig, $height_orig) = getimagesize($uploadfile);
if( $width_orig > 800 || $height_orig > 800 ) {
$width = 800;
$height = 800;
if ($width && ($width_orig < $height_orig)) {
$width = ($height / $height_orig) * $width_orig;
} else {
$height = ($width / $width_orig) * $height_orig;
}
What I was thinking, though, is that it would not be hard to tweak this code to set it up as an option within the ZenPhoto administration. Just clean up the code a bit and insert it into an "if statement". That way the user may specify if it is turned on or not. The height and width should also then be specified in the Admin menu.
Hope this helps. (I don't think the code is quite as pollished as it should be, but it works for my purposes.) Thanks for the great program!
Comments
I love ZenPhoto!!! congratulations
this code hack image:
i dont reduce the images to 800, i dont know the problem.
this is my code in the admin.php in if ($action == "upload"):
help please!!! i need that the images to reduce to upload to 800 px maxime and not to original size of the pictures.
thankkkk!!!
** UPLOAD IMAGES *************************************************************/
/*****************************************************************************/
} else if ($action == "upload") {
// Check for files.
$files_empty = true;
if (isset($_FILES['files']))
foreach($_FILES['files']['name'] as $name) { if (!empty($name)) $files_empty = false; }
// Make sure the folder exists. If not, create it.
if (isset($_POST['processed'])
&& !empty($_POST['folder'])
&& !$files_empty) {
$folder = strip($_POST['folder']);
$uploaddir = SERVERPATH . '/albums/' . $folder;
if (!is_dir($uploaddir)) {
mkdir ($uploaddir, 0777);
}
@chmod($uploaddir,0777);
$error = false;
foreach ($_FILES['files']['error'] as $key => $error) {
if ($_FILES['files']['name'][$key] == "") continue;
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES['files']['tmp_name'][$key];
$name = $_FILES['files']['name'][$key];
if (is_image($name)) {
$uploadfile = $uploaddir . '/' . $name;
move_uploaded_file($tmp_name, $uploadfile);
@chmod($uploadfile, 0777);
// Image Scaling Hack!!
list($width_orig, $height_orig) = getimagesize($uploadfile);
$width = 800;
$height = 800;
if ($width && ($width_orig < $height_orig)) {
$width = ($height / $height_orig) * $width_orig;
} else {
$height = ($width / $width_orig) * $height_orig;
}
//fin Image Scaling Hack!!
} else if (is_zip($name)) {
unzip($tmp_name, $uploaddir);
}
}
}
$album = new Album($gallery, $folder);
$title = strip($_POST['albumtitle']);
if (!empty($title)) {
$album->setTitle($title);
$album->save();
}
header("Location: " . FULLWEBPATH . "/zen/admin.php?page=edit&album=$folder");
exit();
} else {
// Handle the error and return to the upload page.
$page = "upload";
$error = true;
if ($files_empty) {
$errormsg = "You must upload at least one file.";
} else if (empty($_POST['albumtitle'])) {
$errormsg = "You must enter a title for your new album.";
} else if (empty($_POST['folder'])) {
$errormsg = "You must enter a folder name for your new album.";
} else if (empty($_POST['processed'])) {
$errormsg = "You've most likely exceeded the upload limits. Try uploading fewer files at a time, or use a ZIP file.";
} else {
$errormsg = "There was an error submitting the form. Please try again. If this keeps happening, check your "
. "server and PHP configuration (make sure file uploads are enabled, and upload_max_filesize is set high enough). "
. "If you think this is a bug, file a bug report. Thanks!";
}
}
// Image Scaling Hack!!
list($width_orig, $height_orig) = getimagesize($uploadfile);
if( $width_orig > 800 || $height_orig > 800 ) {
$width = 800;
$height = 800;
if ($width && ($width_orig < $height_orig)) {
$width = ($height / $height_orig) * $width_orig;
} else {
$height = ($width / $width_orig) * $height_orig;
}
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($uploadfile);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
imagejpeg($image_p, $uploadfile, 100);
// End Image Scaling Hack
thank
Parse error: syntax error, unexpected T_ELSE in ..../admin.php on line 153
Any help greatly appreciated.