I’m trying to use the photo gallery module to store a few thousand photos for a photo sharing web site with about 800 members (it won’t get much bigger, it’s an internal site for my job).
So I’ve got a few thousand photos, spread out over a handful of folders (which would be categories). What’s the best way to import and process (make thumbnails, medium images, etc) these photos for EE? Is the batch option the way to go here?
Also, is there some documentation somewhere about creating custom front-ends for data entry, if I wanted more than 6 custom fields in the gallery module for example, or if I wanted to tack on some extra processing, how would I get started with that? I’m just looking for a starting point here; not a hand out solution.
Thanks!
So I’ve got a few thousand photos, spread out over a handful of folders (which would be categories). What’s the best way to import and process (make thumbnails, medium images, etc) these photos for EE? Is the batch option the way to go here?
I would be tempted to write some kind of import script to directly load the photos into the system and DB. There are only a few tables to deal with so it shouldn’t be that bad if all the photos will be in the same category.
OK, assuming your host has mysqli installed in its PHP installation, put the following in a template, turn PHP on, replace the appropriate variables with your information then run the template.
Please be warned that there is little error checking and handling and this only works with one author/gallery/category.
But, it will get all the images in there.
PLEASE, PLEASE, PLEASE back up your DB before running this.
I take no responsibility for the results of this code!
<?php
$dir = '</path/to/images/';
$gal = <gallery_ID>;
$cat = <category id>;
$author = <author id>;
// read the files in the directory
$files = scandir($dir);
$mysqli = new mysqli("<DB HOST>", "<DB user>", "<db pwd>, "<EE DB>");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$stmt = $mysqli->prepare("INSERT INTO exp_gallery_entries (gallery_id, cat_id, author_id, filename, extension, title, width, height, entry_date) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param('iiisssiii', $gal, $cat, $author, $name, $ext, $title, $width, $height, $ts);
foreach ($files as $filename)
{
list($name, $ext) = explode(".", $filename);
if ($ext == "JPG")
{
echo "Uploading $name.$ext<br>";
$title = "$name.$ext";
list($width, $height) = getimagesize("/home/edalzell/thedalzells.org/tmp/$title");
$ts = time();
/* execute query */
$stmt->execute();
rename("$dir$title", "/path/to/photos/in/ee/including/cat/folder/$title");
}
}
/* close statement */
$stmt->close();
/* close connection */
$mysqli->close();
?>
I haven’t tested this one, but this is much cleaner and only requires you to change 3 things, gallery_id, cat_id and author_id.
<?php
global $DB;
$gallery_id = <gallery_ID>;
$cat_id = <category id>;
$author_id = <author id>;
require PATH_CORE.'core.image_lib'.EXT;
$IM = new Image_lib();
//get the gallery batch upload folder
$results = $DB->query("SELECT * FROM exp_galleries WHERE gallery_id = $gallery_id");
$gallery_batch_path = $results->row['gallery_batch_path'];
$gallery_path = $results->row['gallery_upload_path'];
// get the category path (if the setting exists)
$results = $DB->query("SELECT * FROM exp_gallery_categories WHERE cat_id = $cat_id AND gallery_id = $gallery_id");
$cat_folder = $results->row['cat_folder'];
// read the files in the directory
$files = scandir($gallery_batch_path);
foreach ($files as $filename)
{
list($name, $ext) = explode(".", $filename);
if (strtolower($ext) == "jpg")
{
echo "Uploading $filename<br>";
$uploaded_image_path = $FNS->remove_double_slashes($gallery_batch_path.'/'.$filename);
$IM->get_image_properties($uploaded_image_path);
$data = array( 'gallery_id' => $gallery_id,
'cat_id' => $cat_id,
'author_id' => $author_id,
'filename' => $name,
'extension' => $ext,
'title' => $filename,
'width' => $width,
'height' => $height,
'entry_date' => time() );
$sql = $DB->insert_string('exp_gallery_entries', $data);
$DB->query($sql);
// now move the file
rename($uploaded_image_path, $FNS->remove_double_slashes($gallery_path.'/'.$cat_folder.'/'.$filename));
}
}
?>
OK, I have created a module that does this now, so you don’t have to change anything. It is a tad rough around the edges, but it does work.
The only downside is that no thumbnails are created, but I will look into that as well.
Is there any interest in this module? I only made it to learn how to make a module, so if no one wants it, no biggie.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.