1
0

Works, need to fix dirtying on custom size change

This commit is contained in:
colings 2011-01-02 22:19:07 -06:00
parent fca49d1cac
commit f94e71b90b
3 changed files with 58 additions and 48 deletions

View File

@ -18,18 +18,18 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class custom_albums_event_Core {
static function item_edit_form($item, $form) {
if ($item->is_album()) {
$albumCustom = ORM::factory("custom_album")->where("album_id", "=", $item->id)->find();
static function item_edit_form($item, $form) {
if ($item->is_album()) {
$albumCustom = ORM::factory("custom_album")->where("album_id", "=", $item->id)->find();
$thumbdata = $form->edit_item->group("custom_album")->label("Custom Album");
$thumbdata = $form->edit_item->group("custom_album")->label("Custom Album");
if ($albumCustom->loaded()) {
$thumbdata->input("thumbsize")->label(t("Thumbnail size (in pixels)"))->value($albumCustom->thumb_size);
} else {
$thumbdata->input("thumbsize")->label(t("Thumbnail size (in pixels)"));
}
if ($albumCustom->loaded()) {
$thumbdata->input("thumbsize")->label(t("Thumbnail size (in pixels)"))->value($albumCustom->thumb_size);
} else {
$thumbdata->input("thumbsize")->label(t("Thumbnail size (in pixels)"));
}
}
}
static function item_edit_form_completed($item, $form) {
@ -61,4 +61,9 @@ class custom_albums_event_Core {
}
}
}
static function theme_edit_form_completed($form) {
// Update our resize rules, in case the thumbnail or resize size has changed
custom_albums_installer::update_rules();
}
}

View File

@ -18,44 +18,19 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class custom_albums_graphics_Core {
/**
* Resize an image. Valid options are width, height and master. Master is one of the Image
* master dimension constants.
*
* @param string $input_file
* @param string $output_file
* @param array $options
*/
static function resize($input_file, $output_file, $options) {
graphics::init_toolkit();
module::event("graphics_resize", $input_file, $output_file, $options);
if (@filesize($input_file) == 0) {
throw new Exception("@todo EMPTY_INPUT_FILE");
}
static function build_thumb($input_file, $output_file, $options) {
$albumCustom = ORM::factory("custom_album")->where("album_id", "=", $options["parent_id"])->find();
// If this album has custom data, build the thumbnail at the specified size
if ($albumCustom->loaded()) {
$thumb_size = $albumCustom->thumb_size;
$dims = getimagesize($input_file);
if (max($dims[0], $dims[1]) < $thumb_size) {
// Image would get upscaled; do nothing
copy($input_file, $output_file);
} else {
$image = Image::factory($input_file)
->resize($thumb_size, $thumb_size, $options["master"])
->quality(module::get_var("gallery", "image_quality"));
if (graphics::can("sharpen")) {
$image->sharpen(module::get_var("gallery", "image_sharpen"));
}
$image->save($output_file);
}
$options["width"] = $albumCustom->thumb_size;
$options["height"] = $albumCustom->thumb_size;
}
module::event("graphics_resize_completed", $input_file, $output_file, $options);
gallery_graphics::resize($input_file, $output_file, $options);
}
static function build_resize($input_file, $output_file, $options) {
gallery_graphics::resize($input_file, $output_file, $options);
}
}

View File

@ -19,12 +19,6 @@
*/
class custom_albums_installer {
static function install() {
// Add rules for generating our thumbnails and resizes
graphics::add_rule(
"gallery", "thumb", "custom_albums::resize",
array("width" => 0, "height" => 0, "master" => Image::AUTO),
200);
// Create a table to store custom album info in.
$db = Database::instance();
@ -38,6 +32,8 @@ class custom_albums_installer {
) DEFAULT CHARSET=utf8;"
);
custom_albums_installer::update_rules();
module::set_version("custom_albums", 1);
}
@ -47,4 +43,38 @@ class custom_albums_installer {
$db->query("DROP TABLE IF EXISTS {custom_albums};");
module::delete("custom_albums");
}
static function update_rules() {
// Make sure our thumb size matches the gallery one
$thumb_size = module::get_var("gallery", "thumb_size");
if ($thumb_size != module::get_var("custom_albums", "thumb_size")) {
// Remove and readd our rule with the latest thumb size
graphics::remove_rule("custom_albums", "thumb", "custom_albums_graphics::build_thumb");
graphics::add_rule(
"custom_albums", "thumb", "custom_albums_graphics::build_thumb",
array("width" => $thumb_size, "height" => $thumb_size, "master" => Image::AUTO),
101);
// Deactivate the gallery thumbnail generation, we'll handle it now
graphics::deactivate_rules("gallery");
module::set_var("custom_albums", "thumb_size", $thumb_size);
}
// Make sure our resize size matches the gallery one
$resize_size = module::get_var("gallery", "resize_size");
if ($resize_size != module::get_var("custom_albums", "resize_size")) {
// Remove and readd our rule with the latest resize size
graphics::remove_rule("custom_albums", "resize", "custom_albums_graphics::build_resize");
graphics::add_rule(
"custom_albums", "resize", "custom_albums_graphics::build_resize",
array("width" => $resize_size, "height" => $resize_size, "master" => Image::AUTO),
101);
// Deactivate the gallery resize, we'll handle it now
graphics::deactivate_rules("gallery");
module::set_var("custom_albums", "resize_size", $resize_size);
}
}
}