예제 #1
0
 /**
  * test thumbnail() method.
  *
  * @return void
  */
 public function testThumbnail()
 {
     $this->assertNotEmpty(ImageToolbox::thumbnail($this->img1, 'thumbnail'));
     $this->assertNotEmpty(ImageToolbox::thumbnail($this->img2, 'thumbnail'));
 }
 /**
  * Returns an scaled version of the given file image.
  *
  * The following GET variables must be set on request:
  *
  * - file: The image's file name to scale.
  * - size: A preview size name, sett `ImageToolbox::getPreviews()`
  *
  * If any of these variables is not present an exception will be throw.
  *
  * @param string $name EAV attribute name
  * @return \Cake\Network\Response
  * @throws \Cake\Network\Exception\NotFoundException When field instance
  *  is not found.
  */
 public function thumbnail($name)
 {
     $this->loadModel('Field.FieldInstances');
     $instance = $this->_getInstance($name);
     if (!$instance) {
         throw new NotFoundException(__d('field', 'Invalid field instance.'), 400);
     }
     if (empty($this->request->query['file'])) {
         throw new NotFoundException(__d('field', 'Invalid file name.'), 400);
     }
     if (empty($this->request->query['size'])) {
         throw new NotFoundException(__d('field', 'Invalid image size.'), 400);
     }
     $imagePath = normalizePath(WWW_ROOT . "/files/{$instance->settings['upload_folder']}/{$this->request->query['file']}");
     $tmb = ImageToolbox::thumbnail($imagePath, $this->request->query['size']);
     if ($tmb !== false) {
         $this->response->file($tmb);
         return $this->response;
     }
     throw new NotFoundException(__d('field', 'Thumbnail could not be found, check write permissions?'), 500);
 }