/** * * @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(); }
//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; }