From 2502240ce4ad25e9fb60ee2468764e25346d2917 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 23 Dec 2008 04:14:07 +0000 Subject: Add very simple graphics toolkits. Track a set of rules in Graphics_Rule_Model which specify how we turn original images into thumbnails and resizes. There's one set of rules that applies to every image in the Gallery. Track the state of thumbs and resizes with a "dirty" bit. The new graphics helper manages the rules and can rebuild the thumbs and resizes for any images that are considered "dirty". Introduce the concept of an "album cover" which is an item that an album points to. We'll use that item as the source for the album's thumbnail/resize. Conflated with this change (sorry!) I also changed the Var table to use module_name instead of module_id. This may be marginally less efficient, but it's much easier to follow in the database. --- core/helpers/photo.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'core/helpers/photo.php') diff --git a/core/helpers/photo.php b/core/helpers/photo.php index 929f96de..8c826e1c 100644 --- a/core/helpers/photo.php +++ b/core/helpers/photo.php @@ -58,6 +58,8 @@ class photo_Core { $photo->width = $image_info[0]; $photo->height = $image_info[1]; $photo->mime_type = empty($image_info['mime']) ? "application/unknown" : $image_info['mime']; + $photo->thumb_dirty = 1; + $photo->resize_dirty = 1; // Randomize the name if there's a conflict while (ORM::Factory("item") @@ -77,18 +79,18 @@ class photo_Core { $photo->add_to_parent($parent); copy($filename, $photo->file_path()); - // This saves the photo a second time, which is unfortunate but difficult to avoid - // because the ORM_MPTT code needs to do the first save. - $thumb_size = module::get_var("core", "thumb_size"); - $resize_size = module::get_var("core", "resize_size"); - - $result = $photo->set_thumb($filename, $thumb_size, $thumb_size) - ->set_resize($filename, $resize_size, $resize_size) - ->save(); - module::event("photo_created", $photo); - return $result; + // Build our thumbnail/resizes + graphics::generate($photo); + + // If the parent has no cover item, make this it. + $parent = $photo->parent(); + if ($parent->album_cover_item_id == null) { + $parent->album_cover_item_id = $photo->id; + $parent->save(); + graphics::generate($parent); + } } static function get_add_form($parent) { -- cgit v1.2.3