private function uploadImage($file, $location, $method, $width, $height)
 {
     $filename = 'uvis' . uniqid('', true) . '.' . $file->getClientOriginalExtension();
     \Tinify\setKey(\Config::get('services.tinify.key'));
     $image = \Tinify\fromBuffer(file_get_contents($file))->resize(array('method' => $method, 'width' => $width, 'height' => $height))->toBuffer();
     Storage::disk('s3')->put($location . '/' . $filename, $image);
     Storage::disk('s3')->setVisibility($location . '/' . $filename, 'public');
     return 'http://d4p17temvc0sy.cloudfront.net/' . $location . '/' . $filename;
 }
Example #2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param SlidersRequest|Request $request
  * @return \Illuminate\Http\Response
  */
 public function store(SlidersRequest $request)
 {
     $file = $request->file('picture');
     $filename = 'oshu' . uniqid('', true) . '.' . $file->getClientOriginalExtension();
     \Tinify\setKey(\Config::get('services.tinify.key'));
     $image = \Tinify\fromBuffer(file_get_contents($file))->resize(array('method' => 'scale', 'height' => 299))->toBuffer();
     Storage::disk('s3')->put('oshu/' . $filename, $image);
     Storage::disk('s3')->setVisibility('oshu/' . $filename, 'public');
     $slider = new Slider();
     $slider->title = $request->title;
     $slider->picture = 'http://cdn.oshu.nl/' . $filename;
     $slider->save();
     Flash::success('Slider opgeslagen');
     return redirect('admin/sliders');
 }
Example #3
0
 public function upload(Request $request)
 {
     $file = $request->file('file');
     $v = Validator::make($request->all(), ['file' => 'required|mimes:jpeg,jpg,png|max:10000']);
     if ($v->fails()) {
         return Response::json(['error' => $v->errors()]);
     }
     //Use some method to generate your filename here. Here we are just using the ID of the image
     $filename = 'oshu' . uniqid('', true) . '.' . $file->getClientOriginalExtension();
     //Push file to S3
     \Tinify\setKey(\Config::get('services.tinify.key'));
     $image = \Tinify\fromBuffer(file_get_contents($file))->resize(array('method' => 'cover', 'width' => 175, 'height' => 175))->toBuffer();
     $move = Storage::disk('s3')->put('oshu/' . $filename, $image);
     Storage::disk('s3')->setVisibility('oshu/' . $filename, 'public');
     if ($move) {
         return Response::json(['file' => ['filelink' => ['http://cdn.oshu.nl/' . $filename]]]);
     } else {
         return Response::json(['error' => true]);
     }
 }
 protected function compress($input, $resize_opts, $preserve_opts)
 {
     try {
         $this->last_error_code = 0;
         $this->set_request_options(\Tinify\Tinify::getClient());
         $source = \Tinify\fromBuffer($input);
         if ($resize_opts) {
             $source = $source->resize($resize_opts);
         }
         if ($preserve_opts) {
             $source = $source->preserve($preserve_opts);
         }
         $result = $source->result();
         $meta = array('input' => array('size' => strlen($input), 'type' => $result->mediaType()), 'output' => array('size' => $result->size(), 'type' => $result->mediaType(), 'width' => $result->width(), 'height' => $result->height(), 'ratio' => round($result->size() / strlen($input), 4)));
         $buffer = $result->toBuffer();
         return array($buffer, $meta);
     } catch (\Tinify\Exception $err) {
         $this->last_error_code = $err->status;
         throw new Tiny_Exception($err->getMessage(), get_class($err), $err->status);
     }
 }
Example #5
0
 public function testFromBufferShouldReturnSource()
 {
     CurlMock::register("https://api.tinify.com/shrink", array("status" => 201, "headers" => array("Location" => "https://api.tinify.com/some/location")));
     Tinify\setKey("valid");
     $this->assertInstanceOf("Tinify\\Source", Tinify\fromBuffer("png file"));
 }