From ae00f739445717885e2fc82e241bae38b7e58d44 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 5 Nov 2008 09:42:47 +0000 Subject: * Add thumbnail and resize dimensions to the item table and use them properly in the theme. * Move thumbnail and resize generation down into the model for consistency. * Add a sample thumbnail for albums * Fix a bug in the ORM to clear the cache when we reload an object. * Add Kohana docs to the scaffold. --- core/helpers/album.php | 13 +++++++++++++ core/helpers/core_installer.php | 4 ++++ core/helpers/photo.php | 15 ++++++++------- 3 files changed, 25 insertions(+), 7 deletions(-) (limited to 'core/helpers') diff --git a/core/helpers/album.php b/core/helpers/album.php index 021c09f3..6934932e 100644 --- a/core/helpers/album.php +++ b/core/helpers/album.php @@ -54,4 +54,17 @@ class Album_Core { } return $album; } + + static function set_thumbnail($id, $filename) { + $album = ORM::factory("item", $id); + + /** @todo: parameterize these dimensions */ + $image = Image::factory($filename); + $image->resize(200, 140, Image::WIDTH)->save($album->thumbnail_path()); + + $dims = getimagesize($album->thumbnail_path()); + $album->thumbnail_width = $dims[0]; + $album->thumbnail_height = $dims[1]; + return $album->save(); + } } diff --git a/core/helpers/core_installer.php b/core/helpers/core_installer.php index 7d83236a..bbcf9bd1 100644 --- a/core/helpers/core_installer.php +++ b/core/helpers/core_installer.php @@ -49,6 +49,10 @@ class core_installer { `right` int(9) NOT NULL, `parent_id` int(9) NOT NULL, `level` int(9) NOT NULL, + `thumbnail_width` int(9) default NULL, + `thumbnail_height` int(9) default NULL, + `resize_width` int(9) default NULL, + `resize_height` int(9) default NULL, PRIMARY KEY (`id`), KEY `parent_id` (`parent_id`), KEY `type` (`type`)) diff --git a/core/helpers/photo.php b/core/helpers/photo.php index dfa67e2b..ef94f52b 100644 --- a/core/helpers/photo.php +++ b/core/helpers/photo.php @@ -52,14 +52,15 @@ class Photo_Core { $photo->name = rand() . "." . $pi["extension"]; } - $photo->add_to_parent($parent_id); - copy($filename, $photo->file_path()); - /** @todo: parameterize these values */ - $image = Image::factory($filename); - $image->resize(200, 140, Image::WIDTH)->save($photo->thumbnail_path()); - $image->resize(800, 600, Image::WIDTH)->save($photo->resize_path()); - return $photo; + // This saves the photo + $photo->add_to_parent($parent_id); + + /** @todo: parameterize these dimensions */ + // This saves the photo a second time, which is unfortunate but difficult to avoid. + return $photo->set_thumbnail($filename, 200, 140) + ->set_resize($filename, 800, 600) + ->save(); } } -- cgit v1.2.3