getSourceSetWidths(); if ('BE' === TYPO3_MODE) { FrontendSimulationUtility::simulateFrontendEnvironment(); } $format = $this->arguments['format']; $quality = $this->arguments['quality']; $treatIdAsReference = (boolean) $this->arguments['treatIdAsReference']; $imageSources = array(); $srcsetVariants = array(); foreach ($srcsets as $key => $width) { $srcsetVariant = $this->getImgResource($src, $width, $format, $quality, $treatIdAsReference); $srcsetVariantSrc = rawurldecode($srcsetVariant[3]); $srcsetVariantSrc = $this->preprocessSourceUri(GeneralUtility::rawUrlEncodeFP($srcsetVariantSrc)); $imageSources[$srcsetVariant[0]] = array( 'src' => $srcsetVariantSrc, 'width' => $srcsetVariant[0], 'height' => $srcsetVariant[1], ); $srcsetVariants[$srcsetVariant[0]] = $srcsetVariantSrc . ' ' . $srcsetVariant[0] . 'w'; } $tag->addAttribute('srcset', implode(',', $srcsetVariants)); if ('BE' === TYPO3_MODE) { FrontendSimulationUtility::resetFrontendEnvironment(); } return $imageSources; } /** * generates a copy of a give image with a specific width * * @param string $src path of the image to convert * @param integer $width width to convert the image to * @param string $format format of the resulting copy * @param string $quality quality of the resulting copy * @param string $treatIdAsReference given src argument is a sys_file_reference record * @param array $params additional params for the image rendering * @return string */ public function getImgResource($src, $width, $format, $quality, $treatIdAsReference, $params = NULL) { $setup = array( 'width' => $width, 'treatIdAsReference' => $treatIdAsReference ); if (FALSE === empty($format)) { $setup['ext'] = $format; } if (0 < intval($quality)) { $quality = MathUtility::forceIntegerInRange($quality, 10, 100, 75); $setup['params'] .= ' -quality ' . $quality; } if ('BE' === TYPO3_MODE && '../' === substr($src, 0, 3)) { $src = substr($src, 3); } return $this->contentObject->getImgResource($src, $setup); } /** * returns an array of srcsets based on the mixed ViewHelper * input (list, csv, array, iterator) * * @return array */ public function getSourceSetWidths() { $srcsets = $this->arguments['srcset']; if (TRUE === $srcsets instanceof \Traversable) { $srcsets = iterator_to_array($srcsets); } elseif (TRUE === is_string($srcsets)) { $srcsets = GeneralUtility::trimExplode(',', $srcsets, TRUE); } else { $srcsets = (array) $srcsets; } return $srcsets; } }