コード例 #1
0
 /**
  * Helper to return image of the current image.
  *
  * @param string $type Derivative type of the image.
  * @return void
  */
 protected function _sendImage($type = null)
 {
     $request = $this->getRequest();
     $itemId = $request->getParam('id');
     $item = get_record_by_id('item', $itemId);
     if (empty($item)) {
         throw new Omeka_Controller_Exception_404();
     }
     $index = $request->getParam('image');
     // Get the index.
     if ($index != '000') {
         $index = preg_replace('`^[0]*`', '', $index);
         $index--;
     } else {
         $index = 0;
     }
     $bookreader = new BookReader($item);
     $part = $request->getParam('part');
     $bookreader->setPart($part);
     if (is_null($type)) {
         $scale = $request->getParam('scale');
         $type = $bookreader->getSizeType($scale);
         // Set a default, even it's normally useless.
         $type = $type ?: 'fullsize';
     }
     $imagesFiles = $bookreader->getLeaves();
     $file = $imagesFiles[$index];
     // No file, so a blank image
     if (empty($file)) {
         $filepath = 'images/blank.png';
         $image = file_get_contents(physical_path_to($filepath));
         $this->getResponse()->clearBody();
         $this->getResponse()->setHeader('Content-Type', 'image/jpeg');
         $this->getResponse()->setBody($image);
     } else {
         $this->_helper->redirector->gotoUrlAndExit($file->getWebPath($type));
     }
 }