Beispiel #1
0
 public function image($request)
 {
     if (!$request->request->has('image')) {
         return new Response('Image URI is missing', 400);
     }
     $uri = $request->request->get('image');
     if (!$request->request->has('data')) {
         return new Response('Image transformation data is missing', 400);
     }
     $data = $request->request->get('data');
     if (!$this->ctx['fs']->has($uri)) {
         return new Response("Source image not found ({$uri})", 400);
     }
     $img = WideImage::loadFromString($this->ctx['fs']->read($uri));
     if (Utils::isResourceUrl($uri)) {
         $info = Utils::resurlinfo($uri);
     } else {
         $pathinfo = pathinfo($uri);
         $info = array('name' => $pathinfo['filename'], 'ext' => $pathinfo['extension']);
     }
     $datas = explode(':', $data);
     $left = $datas[0];
     $top = $datas[1];
     $width = $datas[2];
     $height = $datas[3];
     $filename = $info['name'];
     $ext = $info['ext'];
     $img = $this->transform_image($img, $top, $left, $width, $height);
     // generate image set
     $res = $this->generateImageSet($img, $filename, $ext);
     $res = array('status' => 0, 'srcset' => $res['srcset'], 'ratio' => $res['ratio']);
     return $this->json($request, $res, 200);
 }
Beispiel #2
0
 function test_resurlinfo()
 {
     $info = Utils::resurlinfo('p1/p2/name-sc1234567890abcDEF.ex');
     $this->assertEquals(array('path' => 'p1/p2', 'name' => 'name', 'id' => '1234567890abc', 'subid' => 'DEF', 'ext' => 'ex'), $info);
     $info = Utils::resurlinfo('n-a.me-sc1234567890abc.ex');
     $this->assertEquals(array('path' => '', 'name' => 'n-a.me', 'id' => '1234567890abc', 'subid' => '', 'ext' => 'ex'), $info);
     $info = Utils::resurlinfo(array('p1/n1-sc1234567890123.ext', 'p2/n2-sc1234567890123.ext'));
     $this->assertEquals(array(array('path' => 'p1', 'name' => 'n1', 'id' => '1234567890123', 'subid' => '', 'ext' => 'ext'), array('path' => 'p2', 'name' => 'n2', 'id' => '1234567890123', 'subid' => '', 'ext' => 'ext')), $info);
 }