original_string: public function derivatives($min_width, $max_width = 2500, $step = 200)
      {
          if (!empty($this->alternatives)) {
              $max = max(array_keys($this->alternatives));
              $base = $this->alternatives[$max];
          } else {
              $base = $this;
          }
  
          $widths = [];
  
          if (func_num_args() === 1) {
              foreach ((array) func_get_arg(0) as $width) {
                  if ($width < $base->get('width')) {
                      $widths[] = $width;
                  }
              }
          } else {
              $max_width = min($max_width, $base->get('width'));
  
              for ($width = $min_width; $width < $max_width; $width = $width + $step) {
                  $widths[] = $width;
              }
          }
  
          foreach ($widths as $width) {
              // Only generate image alternatives that don't already exist
              if (array_key_exists((int) $width, $this->alternatives)) {
                  continue;
              }
  
              $derivative = MediumFactory::fromFile($base->get('filepath'));
  
              // It's possible that MediumFactory::fromFile returns null if the
              // original image file no longer exists and this class instance was
              // retrieved from the page cache
              if (null !== $derivative) {
                  $index = 2;
                  $alt_widths = array_keys($this->alternatives);
                  sort($alt_widths);
  
                  foreach ($alt_widths as $i => $key) {
                      if ($width > $key) {
                          $index += max($i, 1);
                      }
                  }
  
                  $basename = preg_replace('/(@\d+x){0,1}$/', "@{$width}w", $base->get('basename'), 1);
                  $derivative->setImagePrettyName($basename);
  
                  $ratio = $base->get('width') / $width;
                  $height = $derivative->get('height') / $ratio;
  
                  $derivative->resize($width, $height);
                  $derivative->set('width', $width);
                  $derivative->set('height', $height);
  
                  $this->addAlternative($ratio, $derivative);
              }
          }
  
          return $this;
      }
code: public function derivatives($min_width, $max_width = 2500, $step = 200)
      {
          if (!empty($this->alternatives)) {
              $max = max(array_keys($this->alternatives));
              $base = $this->alternatives[$max];
          } else {
              $base = $this;
          }
  
          $widths = [];
  
          if (func_num_args() === 1) {
              foreach ((array) func_get_arg(0) as $width) {
                  if ($width < $base->get('width')) {
                      $widths[] = $width;
                  }
              }
          } else {
              $max_width = min($max_width, $base->get('width'));
  
              for ($width = $min_width; $width < $max_width; $width = $width + $step) {
                  $widths[] = $width;
              }
          }
  
          foreach ($widths as $width) {
              // Only generate image alternatives that don't already exist
              if (array_key_exists((int) $width, $this->alternatives)) {
                  continue;
              }
  
              $derivative = MediumFactory::fromFile($base->get('filepath'));
  
              // It's possible that MediumFactory::fromFile returns null if the
              // original image file no longer exists and this class instance was
              // retrieved from the page cache
              if (null !== $derivative) {
                  $index = 2;
                  $alt_widths = array_keys($this->alternatives);
                  sort($alt_widths);
  
                  foreach ($alt_widths as $i => $key) {
                      if ($width > $key) {
                          $index += max($i, 1);
                      }
                  }
  
                  $basename = preg_replace('/(@\d+x){0,1}$/', "@{$width}w", $base->get('basename'), 1);
                  $derivative->setImagePrettyName($basename);
  
                  $ratio = $base->get('width') / $width;
                  $height = $derivative->get('height') / $ratio;
  
                  $derivative->resize($width, $height);
                  $derivative->set('width', $width);
                  $derivative->set('height', $height);
  
                  $this->addAlternative($ratio, $derivative);
              }
          }
  
          return $this;
      }
code_tokens: public function derivatives ( $ min_width , $ max_width = 2500 , $ step = 200 ) { if ( ! empty ( $ this -> alternatives ) ) { $ max = max ( array_keys ( $ this -> alternatives ) ) ; $ base = $ this -> alternatives [ $ max ] ; } else { $ base = $ this ; } $ widths = [ ] ; if ( func_num_args ( ) === 1 ) { foreach ( ( array ) func_get_arg ( 0 ) as $ width ) { if ( $ width < $ base -> get ( 'width' ) ) { $ widths [ ] = $ width ; } } } else { $ max_width = min ( $ max_width , $ base -> get ( 'width' ) ) ; for ( $ width = $ min_width ; $ width < $ max_width ; $ width = $ width + $ step ) { $ widths [ ] = $ width ; } } foreach ( $ widths as $ width ) { // Only generate image alternatives that don't already exist if ( array_key_exists ( ( int ) $ width , $ this -> alternatives ) ) { continue ; } $ derivative = MediumFactory :: fromFile ( $ base -> get ( 'filepath' ) ) ; // It's possible that MediumFactory::fromFile returns null if the // original image file no longer exists and this class instance was // retrieved from the page cache if ( null !== $ derivative ) { $ index = 2 ; $ alt_widths = array_keys ( $ this -> alternatives ) ; sort ( $ alt_widths ) ; foreach ( $ alt_widths as $ i => $ key ) { if ( $ width > $ key ) { $ index += max ( $ i , 1 ) ; } } $ basename = preg_replace ( '/(@\d+x){0,1}$/' , "@{$width}w" , $ base -> get ( 'basename' ) , 1 ) ; $ derivative -> setImagePrettyName ( $ basename ) ; $ ratio = $ base -> get ( 'width' ) / $ width ; $ height = $ derivative -> get ( 'height' ) / $ ratio ; $ derivative -> resize ( $ width , $ height ) ; $ derivative -> set ( 'width' , $ width ) ; $ derivative -> set ( 'height' , $ height ) ; $ this -> addAlternative ( $ ratio , $ derivative ) ; } } return $ this ; }
docstring: Generate alternative image widths, using either an array of integers, or
  a min width, a max width, and a step parameter to fill out the necessary
  widths. Existing image alternatives won't be overwritten.
  
  @param  int|int[] $min_width
  @param  int       $max_width
  @param  int       $step
  @return $this
docstring_tokens: Generate alternative image widths using either an array of integers or a min width a max width and a step parameter to fill out the necessary widths . Existing image alternatives won t be overwritten .