/**
  * @see \ResponsiveImages\SrcsetGeneratorInterface
  *
  * @param string    $uri
  *   Drupal URI to the original image file.
  * @param RImg\Size $size
  *
  * @return RImg\Src[]
  */
 public function listFor($uri, RImg\Size $size)
 {
     $styles = $this->stylesMatchingSize($size);
     # By default Drupal doesn't provide an image style that crops an image to
     # an aspect ratio without potentially upscaling it. If the original image is
     # smaller than the styles that are returned we aren't providing any better
     # quality. Better to just allow only one larger than the original, or even
     # the original if it matches the aspect ratio.
     $image = image_get_info($uri);
     if ($image) {
         $styles = F\partition($styles, function ($style) use($image, $size) {
             return $style->width < $image['width'];
         });
         if ($size->matchesAspectRatio($image['width'] / $image['height']) and (!empty($styles[1]) and F\head($styles[1])->width != $image['width'] or $image['width'] <= $size->getMaxWidth() * 2)) {
             $styles[0][] = (object) ['name' => null, 'width' => $image['width'], 'height' => $image['height'], 'firm' => true];
         } else {
             if (!empty($styles[1])) {
                 $styles[0][] = F\head($styles[1]);
             }
         }
         $styles = $styles[0];
     }
     return F\map($styles, function ($style) use($uri) {
         $url = $style->name ? image_style_url($style->name, $uri) : file_create_url($uri);
         return new RImg\Src($url, $style->width);
     });
 }
Exemplo n.º 2
0
 public function testPassNonCallable()
 {
     $this->expectArgumentError("Argument 2 passed to Functional\\partition() must be callable");
     partition($this->list, 'undefinedFunction');
 }