예제 #1
0
 static function item_before_create($item)
 {
     $max_size = module::get_var("max_size", "max_size", 600);
     if ($item->is_photo()) {
         list($width, $height, $mime_type) = photo::get_file_metadata($item->data_file);
         if ($width > $max_size || $height > $max_size) {
             $tempnam = tempnam(TMPPATH, "size");
             $tmpfile = $tempnam . "." . pathinfo($item->data_file, PATHINFO_EXTENSION);
             gallery_graphics::resize($item->data_file, $tmpfile, array("width" => $max_size, "height" => $max_size, "master" => Image::AUTO));
             rename($tmpfile, $item->data_file);
             unlink($tempnam);
         }
     }
 }
예제 #2
0
 public function generate_album_cover_from_png_test()
 {
     $input_file = MODPATH . "gallery/tests/test.jpg";
     $output_file = TMPPATH . test::random_name() . ".png";
     gallery_graphics::resize($input_file, $output_file, null, null);
     $album = test::random_album();
     $photo = test::random_photo_unsaved($album);
     $photo->set_data_file($output_file);
     $photo->name = "album_cover_from_png.png";
     $photo->save();
     $album->reload();
     // Check that the image was correctly resized and converted to jpg
     $this->assert_equal(array(200, 150, "image/jpeg", "jpg"), photo::get_file_metadata($album->thumb_path()));
     // Check that the items table got updated
     $this->assert_equal(array(200, 150), array($album->thumb_width, $album->thumb_height));
     // Check that the image is not marked dirty
     $this->assert_equal(0, $album->thumb_dirty);
 }
 public function resize_bad_jpg_test()
 {
     // Input is a garbled jpg, output is jpg autofit to 300x300
     $input_file = TMPPATH . test::random_name() . ".jpg";
     $output_file = TMPPATH . test::random_name() . ".jpg";
     $options = array("width" => 300, "height" => 300, "master" => Image::AUTO);
     file_put_contents($input_file, test::lorem_ipsum(200));
     // Should get passed to Image library and throw an exception
     try {
         gallery_graphics::resize($input_file, $output_file, $options, null);
         $this->assert_true(false, "Shouldn't get here");
     } catch (Exception $e) {
         // pass
     }
 }
예제 #4
0
 private static function _replace_image_with_placeholder($item, $target)
 {
     if ($item->is_album() && !$item->album_cover_item_id) {
         $input_path = MODPATH . "gallery/images/missing_album_cover.jpg";
     } else {
         if ($item->is_movie() || $item->is_album() && $item->album_cover()->is_movie()) {
             $input_path = MODPATH . "gallery/images/missing_movie.jpg";
         } else {
             $input_path = MODPATH . "gallery/images/missing_photo.jpg";
         }
     }
     if ($target == "thumb") {
         $output_path = $item->thumb_path();
         $size = module::get_var("gallery", "thumb_size", 200);
     } else {
         $output_path = $item->resize_path();
         $size = module::get_var("gallery", "resize_size", 640);
     }
     $options = array("width" => $size, "height" => $size, "master" => Image::AUTO);
     try {
         // Copy/convert/resize placeholder as needed.
         gallery_graphics::resize($input_path, $output_path, $options, null);
     } catch (Exception $e) {
         // Copy/convert/resize didn't work.  Add to the log and copy the jpg version (which could have
         // a non-jpg extension).  This is less than ideal, but it's better than putting nothing
         // there and causing theme views to act strangely because a file is missing.
         // @todo we should handle this better.
         Kohana_Log::add("error", "Caught exception converting placeholder for missing image: " . $item->title . "\n" . $e->getMessage() . "\n" . $e->getTraceAsString());
         copy($input_path, $output_path);
     }
     if (!file_exists($output_path)) {
         // Copy/convert/resize didn't throw an exception, but still didn't work - do the same as above.
         // @todo we should handle this better.
         Kohana_Log::add("error", "Failed to convert placeholder for missing image: {$item->title}");
         copy($input_path, $output_path);
     }
 }
예제 #5
0
 /**
  * Send the ecard.
  */
 public function send($id)
 {
     $item = ORM::factory("item", $id);
     access::required("view", $item);
     if (!ecard::can_send_ecard()) {
         access::forbidden();
     }
     $form = ecard::get_send_form($item);
     try {
         $valid = $form->validate();
     } catch (ORM_Validation_Exception $e) {
         // Translate ORM validation errors into form error messages
         foreach ($e->validation->errors() as $key => $error) {
             $form->edit_item->inputs[$key]->add_error($error, 1);
         }
         $valid = false;
     }
     if ($valid) {
         $to_array = explode(",", $form->send_ecard->inputs["to_email"]->value);
         foreach ($to_array as $to) {
             $v = new View("ecard_email.html");
             $v->item = $item;
             $v->subject = module::get_var("ecard", "subject");
             $from_name = $form->send_ecard->from_name->value;
             $bcc = module::get_var("ecard", "bcc");
             if ($form->send_ecard->send_to_self->checked == true) {
                 $cc = $form->send_ecard->inputs["from_email"]->value;
             }
             $v->message = t(module::get_var("ecard", "message"), array("fromname" => $from_name));
             $v->custom_message = $form->send_ecard->text->value;
             $v->image = $item->name;
             $from = $form->send_ecard->inputs["from_email"]->value;
             $headers = array("from" => $from_name . "<" . $from . ">", "to" => $to, "subject" => module::get_var("ecard", "subject"));
             require_once MODPATH . "ecard/lib/mime.php";
             $mime = new Mail_mime("\n");
             $mime->setHTMLBody($v->render());
             if ($form->send_ecard->send_fresh->checked == true) {
                 $tmpfile = tempnam(TMPPATH, "clean");
                 if ($form->send_ecard->send_thumbnail->checked == true) {
                     $options = array("width" => module::get_var("gallery", "thumb_size"), "height" => module::get_var("gallery", "thumb_size"), "master" => Image::AUTO);
                     gallery_graphics::resize($item->file_path(), $tmpfile, $options);
                     $mime->addHTMLImage($tmpfile, $item->mime_type, $item->name);
                 } else {
                     $options = array("width" => module::get_var("gallery", "resize_size"), "height" => module::get_var("gallery", "resize_size"), "master" => Image::AUTO);
                     gallery_graphics::resize($item->file_path(), $tmpfile, $options);
                     $mime->addHTMLImage($tmpfile, $item->mime_type, $item->name);
                 }
             } else {
                 if ($form->send_ecard->send_thumbnail->checked == true) {
                     $mime->addHTMLImage($item->thumb_path(), $item->mime_type, $item->name);
                 } else {
                     $mime->addHTMLImage($item->resize_path(), $item->mime_type, $item->name);
                 }
             }
             $body = $mime->get(array('html_charset' => 'UTF-8', 'text_charset' => 'UTF-8', 'text_encoding' => '8bit', 'head_charset' => 'UTF-8'));
             self::_notify($headers['to'], $headers['from'], $headers['subject'], $item, $body, $mime->headers(), $bcc, $cc);
         }
         unlink($tmpfile);
         message::success("eCard successfully sent");
         json::reply(array("result" => "success"));
     } else {
         json::reply(array("result" => "error", "html" => (string) $form));
     }
 }
 static function build_resize($input_file, $output_file, $options)
 {
     gallery_graphics::resize($input_file, $output_file, $options);
 }