public function testRes()
 {
     $image = new ImageResource('Ford Mustang 1972', array('/images/1972_ford_mustang-wide.jpg', '/images/1972_ford_mustang-mini.jpg'), array('root_dir' => __DIR__ . '/tmp', 'output_dir' => '/images/test', 'images' => array(array('index' => 0, 'suffix' => 'test', 'width' => 1000, 'height' => 800, 'format' => 'jpg'), array('index' => 1, 'suffix' => 'ok', 'width' => 300, 'height' => 150, 'format' => 'png'))));
     $url = new UrlManager();
     $url->setBaseUrl('/tmp/');
     $imageStorage = new ImagineImagesStorage();
     $image->setUrlManager($url);
     $image->setImagesStorage($imageStorage);
     $image->save();
     $imagine = new Imagine();
     $size = $imagine->open(__DIR__ . '/tmp/images/test/1972_ford_mustang-mini_ok_300x150.png')->getSize();
     $this->assertEquals(300, $size->getWidth());
     $this->assertEquals(150, $size->getHeight());
     $size = $imagine->open(__DIR__ . '/tmp/images/test/1972_ford_mustang-wide_test_1000x800.jpg')->getSize();
     $this->assertEquals(1000, $size->getWidth());
     $this->assertEquals(800, $size->getHeight());
     $image->cleanup();
     $this->assertEquals(0, count(glob(__DIR__ . "/tmp/images/test/*")));
     $urls = $image->getUrl();
     $this->assertEquals('/tmp/images/test/1972_ford_mustang-wide_test_1000x800.jpg', $urls[0]);
     $this->assertEquals('/tmp/images/test/1972_ford_mustang-mini_ok_300x150.png', $urls[1]);
 }
 /**
  * Kod znacznika <picture>
  * 
  * @param ImageResource $res
  * @param string $output
  */
 protected function render_html_picture(ImageResource $res, &$output)
 {
     $data = $res->imageData();
     $tmp = '';
     $source = function (array &$arr) use(&$data, &$tmp) {
         $tag = new HtmlElement('source');
         $srcset = '';
         foreach ($arr as &$img) {
             $srcset .= $img['url'];
             $srcset .= !empty($img['data']['srcset_x']) ? ' ' . $img['data']['srcset_x'] . 'x' : '';
             $srcset .= ', ';
         }
         $tag->attr('srcset', substr($srcset, 0, -2));
         $index = $arr[0]['data']['media_index'];
         if (isset($data['media'][$index])) {
             $tag->attr('media', $data['media'][$index]);
         }
         $tmp .= $tag->render() . PHP_EOL;
         $tag->destroy($tag);
     };
     foreach ($data as $k => $v) {
         if (is_integer($k) && $k > -1 && is_array($v)) {
             $source($data[$k]);
         }
     }
     if (isset($data[-1])) {
         $source($data[-1]);
     }
     $urls = $res->getUrl();
     $img = new HtmlElement('img');
     $img->attr('src', $urls[$data['src-index']]);
     $img->attr('alt', htmlspecialchars($res->getName()));
     $tag = new HtmlElement('picture');
     //$tag->attr('alt', htmlspecialchars($res->getName()));
     foreach ($data['attr'] as $k => $v) {
         $tag->attr(htmlspecialchars($k), htmlspecialchars($v));
     }
     preg_match('/<picture.*?>/', $tag->render(), $result);
     $output[] = (isset($result[0]) ? $result[0] . PHP_EOL : '<picture>' . PHP_EOL) . "<!--[if IE 9]><video style=\"display: none;\"><![endif]-->" . PHP_EOL . str_replace("</source>", '', $tmp) . "<!--[if IE 9]></video><![endif]-->" . PHP_EOL . $img->render() . PHP_EOL . '</picture>';
     $tag->destroy($tag);
     $img->destroy($img);
 }