예제 #1
0
 public static function createFromUpload(array $file_upload, $options = array())
 {
     if (!isset($file_upload['error']) || is_array($file_upload['error'])) {
         throw new \Exception('Invalid Upload');
     }
     switch ($file_upload['error']) {
         case UPLOAD_ERR_OK:
             break;
         case UPLOAD_ERR_NO_FILE:
             throw new \Exception('No file sent.');
         case UPLOAD_ERR_INI_SIZE:
         case UPLOAD_ERR_FORM_SIZE:
             throw new \Exception('Exceeded filesize limit.');
         default:
             throw new \Exception('Unknown errors.');
     }
     if (empty($file_upload['tmp_name']) || empty($file_upload['name'])) {
         throw new \Exception('Invalid Upload Properties');
     }
     if (empty($file_upload['size'])) {
         throw new \Exception('Invalid Upload Size');
     }
     $app = \Base::instance();
     $options = $options + array('width' => 460, 'height' => 308);
     // Do the upload
     $model = new static();
     $grid = $model->getDb()->getGridFS($model->collectionNameGridFS());
     $file_path = $model->inputFilter()->clean($file_upload['tmp_name']);
     $name = $model->inputFilter()->clean($file_upload['name']);
     //$buffer = file_get_contents($file_upload['tmp_name']);
     //TODO MOVE THIS TO A LISTENER
     $image = new \Dsc\Image($file_upload['tmp_name']);
     $cropped = $image->cropResize(250, 250);
     $cropped = $cropped->crop(250, 250);
     $buffer = $cropped->toBuffer();
     $options['name'] = $file_upload['name'];
     return static::createFromBuffer($buffer, $options);
 }
예제 #2
0
 public function rotate()
 {
     $asset = $this->getItem();
     $length = $asset->length;
     $chunkSize = $asset->chunkSize;
     $chunks = ceil($length / $chunkSize);
     $collChunkName = $asset->collectionNameGridFS() . ".chunks";
     $collChunks = $asset->getDb()->{$collChunkName};
     $binImagedata = null;
     for ($i = 0; $i < $chunks; $i++) {
         $chunk = $collChunks->findOne(array("files_id" => $asset->_id, "n" => $i));
         $binImagedata .= $chunk["data"]->bin;
     }
     $dscImage = new \Dsc\Image(\imagecreatefromstring($binImagedata));
     $dscImage->rotate($this->app->get('PARAMS.degrees'), null, false);
     $buffer = $dscImage->toBuffer();
     $asset->replace($buffer);
     $this->app->reroute('/admin/asset/edit/' . $this->app->get('PARAMS.id'));
 }
예제 #3
0
파일: Assets.php 프로젝트: dioscouri/f3-lib
 /**
  * 
  * @param unknown_type $gd_resource
  * @return binary
  */
 public function getThumbFromGDResource($gd_resource)
 {
     $width = !empty($options['width']) ? (int) $options['width'] : 460;
     $height = !empty($options['height']) ? (int) $options['height'] : 308;
     /*
     $gd_resource = imagecreatefromstring($buffer);
     */
     $image = new \Dsc\Image($gd_resource);
     $thumb = $image->resize($width, $height, false);
     return $thumb->toBuffer();
 }
예제 #4
0
//set last-modified header
header("Last-Modified: " . gmdate("D, d M Y H:i:s", $lastModified) . " GMT");
//set etag-header
header("Etag: {$etagFile}");
//make sure caching is turned on
header('Cache-Control: public');
// set content type header
header('Content-type: ' . $item->get('contentType'));
//check if page has changed. If not, send 304 and exit
if (@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $lastModified || $etagHeader == $etagFile) {
    header("HTTP/1.1 304 Not Modified");
    exit;
}
// display the binary data
$length = $item->get("length");
$chunkSize = $item->get("chunkSize");
$chunks = ceil($length / $chunkSize);
$collChunkName = $model->collectionNameGridFS() . ".chunks";
$collChunks = $model->getDb()->{$collChunkName};
$binImagedata = null;
for ($i = 0; $i < $chunks; $i++) {
    $chunk = $collChunks->findOne(array("files_id" => $item->_id, "n" => $i));
    $binImagedata .= $chunk["data"]->bin;
}
if (!empty($height) && !empty($width)) {
    $img = new \Dsc\Image(imagecreatefromstring($binImagedata));
    $img->resize($width, $height, false);
    echo $img->toBuffer();
} else {
    echo $binImagedata;
}