code: public function beforeToHtml(Image $subject)
      {
          if ($this->config->isImageOptimizationPixelRatioEnabled() !== true) {
              return;
          }
  
          $srcSet = [];
          $imageUrl = $subject->getData('image_url');
          $pixelRatios = $this->config->getImageOptimizationRatios();
          $pixelRatiosArray = explode(',', $pixelRatios);
          $glue = (strpos($imageUrl, '?') !== false) ? '&' : '?';
  
          # Pixel ratios defaults are based on the table from https://mydevice.io/devices/
          # Bulk of devices are 2x however many new devices like Samsung S8, iPhone X etc are 3x and 4x
          foreach ($pixelRatiosArray as $pr) {
              $ratio = 'dpr=' . $pr . ' ' . $pr . 'x';
              $srcSet[] = $imageUrl . $glue . $ratio;
          }
  
          $subject->setData('custom_attributes', 'srcset="' . implode(',', $srcSet) . '"');
      }
docs: Adjust srcset if required
  
  @param Image $subject