.

ImagetoolstestController Class Reference
[ImageTools]

Provide a visual test page for image tools. More...

Inheritance diagram for ImagetoolstestController:
ControllerBase IController IEventSink

List of all members.

Public Member Functions

  action_imagetools_test_image (PageData $page_data, $type)
  Show image.
  action_imagetools_test_index (PageData $page_data)
  Show test main page and handle upload.
  get_routes ()
  Return array of Route instances which are handled by this controller.

Protected Member Functions

  apply_tools ($tmp_file)
  do_upload (PageData $page_data)
  Upload file, and ally tools.

Detailed Description

Provide a visual test page for image tools.

Definition at line 7 of file imagetoolstest.controller.php.


Member Function Documentation

ImagetoolstestController::action_imagetools_test_image ( PageData page_data,
type  
)

Show image.

Definition at line 91 of file imagetoolstest.controller.php.

00091                                                                                  {
00092                 $page_data->page_template = 'emptypage';
00093                 $basepath = Config::get_value(Config::TEMP_DIR) . 'imgtooltest-' . $type;
00094                 foreach(array('jpg' => 'jpeg', 'png' => 'png', 'gif' => 'gif') as $ext => $mime) {
00095                         $path = $basepath . '.' . $ext;
00096                         if (file_exists($path)) {
00097                                 header('Content-Type: image/'. $mime);
00098                                 $page_data->content = file_get_contents($path);
00099                         }
00100                 }
00101                 if (empty($page_data->content)) {
00102                         return self::NOT_FOUND;
00103                 }
00104         }
ImagetoolstestController::action_imagetools_test_index ( PageData page_data  ) 

Show test main page and handle upload.

Definition at line 27 of file imagetoolstest.controller.php.

00027                                                                           {
00028                 $err = new Status();
00029                 if ($page_data->has_post_data()) {
00030                         $err->merge($this->do_upload($page_data));
00031                 }
00032                 
00033                 $page_data->status = $err;
00034                 $view = ViewFactory::create_view(IViewFactory::CONTENT, 'imagetools/test/index', $page_data);
00035                 $view->render();
00036         }
ImagetoolstestController::apply_tools ( tmp_file  )  [protected]

Definition at line 65 of file imagetoolstest.controller.php.

00065                                                   {
00066                 $tmp_dir = Config::get_value(Config::TEMP_DIR);
00067                 Load::components('imagetoolsfactory');
00068                 $tools = ImageToolsFactory::create_imagetools();
00069                 $src = $tools->create_from_file($tmp_file);
00070                 $src->save_to_file($tmp_dir . 'imgtooltest-src');
00071                 
00072                 $resized = $tools->resize($src, 300, 100);
00073                 $resized->save_to_file($tmp_dir . 'imgtooltest-resize');
00074 
00075                 $resized = $tools->resize_fit($src, 300, 100);
00076                 $resized->save_to_file($tmp_dir . 'imgtooltest-resize-fit');
00077                 
00078                 $resized = $tools->crop($src, ($src->get_width() - 100) / 2, ($src->get_height() - 100) / 2, 100, 100);
00079                 $resized->save_to_file($tmp_dir . 'imgtooltest-crop');          
00080                 
00081                 $watermark = $tools->watermark($src);
00082                 $watermark->save_to_file($tmp_dir . 'imgtooltest-watermark');
00083 
00084                 $resized = $tools->fit($src, 300, 100);
00085                 $resized->save_to_file($tmp_dir . 'imgtooltest-fit');
00086         }
ImagetoolstestController::do_upload ( PageData page_data  )  [protected]

Upload file, and ally tools.

Definition at line 41 of file imagetoolstest.controller.php.

00041                                                           {
00042                 $ret = new Status();
00043                 $post_item = $page_data->get_post()->get_item('upload');
00044                 $i_err = Arr::get_item($post_item, 'error', UPLOAD_ERR_NO_FILE);
00045                 switch ($i_err) {
00046                         case UPLOAD_ERR_OK:
00047                                 $tmp_file = Arr::get_item($post_item, 'tmp_name', '');
00048                                 //$org_file = Arr::get_item($post_item, 'name', '');
00049                                 $this->apply_tools($tmp_file);                          
00050                                 break;          
00051                         case UPLOAD_ERR_NO_FILE:
00052                                 $ret->append('No file was uploaded');
00053                                 break;                          
00054                         case UPLOAD_ERR_INI_SIZE:
00055                         case UPLOAD_ERR_FORM_SIZE:
00056                                 $ret->append('The uploaded file is too big');
00057                                 break;
00058                         default:
00059                                 $ret->append('An unknown error code was retrieved while uploading the file.');
00060                                 break;
00061                 }
00062                 return $ret;            
00063         }
ImagetoolstestController::get_routes (  ) 

Return array of Route instances which are handled by this controller.

Returns:
array Array of Routes

Reimplemented from ControllerBase.

Definition at line 13 of file imagetoolstest.controller.php.

00013                                      {
00014                 $ret = array();
00015                 if (Config::has_feature(ConfigImageTools::IS_TEST_CONTROLLER_ENABLED)) {
00016                         $ret = array(
00017                                 new ExactMatchRoute('imagetools/test/', $this, 'imagetools_test_index', new NoCacheCacheManager()),
00018                                 new ParameterizedRoute('imagetools/test/image-{type:e:src,resize,crop,watermark,fit,resize-fit}', $this, 'imagetools_test_image', new NoCacheCacheManager())
00019                         );
00020                 }
00021                 return $ret;
00022         }

The documentation for this class was generated from the following file: