Skip to content

Commit

Permalink
Merge pull request #62 from sitegeist/develop
Browse files Browse the repository at this point in the history
Release of v2
  • Loading branch information
s2b committed Apr 10, 2020
2 parents a242883 + fdf9593 commit 7839c1f
Show file tree
Hide file tree
Showing 36 changed files with 268 additions and 853 deletions.
20 changes: 20 additions & 0 deletions .ecrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"Verbose": false,
"Debug": false,
"IgnoreDefaults": false,
"SpacesAftertabs": false,
"NoColor": false,
"Exclude": [
".Build",
".git",
".DS_Store"
],
"AllowedContentTypes": [],
"PassedFiles": [],
"Disable": {
"EndOfLine": false,
"Indentation": false,
"InsertFinalNewline": false,
"TrimTrailingWhitespace": false
}
}
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
language: php
php:
- '7.0'
- '7.1'
- '7.2'
- '7.3'
- '7.4'
cache:
directories:
- $HOME/.composer/cache/files
before_script:
- phpenv config-rm xdebug.ini
- composer install --prefer-dist
script:
- composer validate
- composer lint
- composer test
49 changes: 0 additions & 49 deletions Classes/Controller/MediaController.php

This file was deleted.

45 changes: 0 additions & 45 deletions Classes/Domain/Model/Page.php

This file was deleted.

8 changes: 0 additions & 8 deletions Classes/Domain/Repository/PageRepository.php

This file was deleted.

73 changes: 27 additions & 46 deletions Classes/Utility/ResponsiveImagesUtility.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

namespace SMS\SmsResponsiveImages\Utility;
namespace Sitegeist\ResponsiveImages\Utility;

use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Resource\FileInterface;
use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection;
use TYPO3\CMS\Core\Imaging\ImageManipulation\Area;
use TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder;
use TYPO3Fluid\Fluid\Core\ViewHelper\TagBuilder;
use TYPO3\CMS\Extbase\Service\ImageService;
use TYPO3\CMS\Core\Utility\GeneralUtility;

Expand Down Expand Up @@ -49,7 +49,6 @@ public function __construct(ImageService $imageService)
* @param Area $focusArea
* @param string $sizesQuery
* @param TagBuilder $tag
* @param bool $picturefillMarkup
* @param bool $absoluteUri
* @param bool $lazyload
* @param array|string $ignoreFileExtensions
Expand All @@ -66,10 +65,9 @@ public function createImageTagWithSrcset(
Area $focusArea = null,
string $sizesQuery = null,
TagBuilder $tag = null,
bool $picturefillMarkup = true,
bool $absoluteUri = false,
bool $lazyload = false,
$ignoreFileExtensions = 'svg',
$ignoreFileExtensions = 'svg, gif',
int $placeholderSize = 0,
bool $placeholderInline = false
): TagBuilder {
Expand All @@ -96,9 +94,8 @@ public function createImageTagWithSrcset(
// if lazyload enabled add data- prefix
$attributePrefix = $lazyload ? 'data-' : '';

if (!$picturefillMarkup) {
$tag->addAttribute($attributePrefix . 'src', $fallbackImageUri);
}
// Add fallback image
$tag->addAttribute($attributePrefix . 'src', $fallbackImageUri);

// Create placeholder image for lazyloading
if ($lazyload && $placeholderSize) {
Expand All @@ -111,6 +108,12 @@ public function createImageTagWithSrcset(
));
}

// Add lazyload class to image tag
if ($lazyload) {
$existingClass = $tag->getAttribute('class');
$tag->addAttribute('class', $existingClass ? $existingClass . ' lazyload' : 'lazyload');
}

// Generate different image sizes for srcset attribute
$srcsetImages = $this->generateSrcsetImages($originalImage, $referenceWidth, $srcset, $cropArea, $absoluteUri);
$srcsetMode = substr(key($srcsetImages), -1); // x or w
Expand Down Expand Up @@ -147,7 +150,6 @@ public function createImageTagWithSrcset(
* @param Area $focusArea
* @param TagBuilder $tag
* @param TagBuilder $fallbackTag
* @param bool $picturefillMarkup
* @param bool $absoluteUri
* @param bool $lazyload
* @param array|string $ignoreFileExtensions
Expand All @@ -164,10 +166,9 @@ public function createPictureTag(
Area $focusArea = null,
TagBuilder $tag = null,
TagBuilder $fallbackTag = null,
bool $picturefillMarkup = true,
bool $absoluteUri = false,
bool $lazyload = false,
$ignoreFileExtensions = 'svg',
$ignoreFileExtensions = 'svg, gif',
int $placeholderSize = 0,
bool $placeholderInline = false
): TagBuilder {
Expand Down Expand Up @@ -195,48 +196,22 @@ public function createPictureTag(
// if lazyload enabled add data- prefix
$attributePrefix = $lazyload ? 'data-' : '';

// Use last breakpoint as fallback image if it doesn't define a media query
$lastBreakpoint = array_pop($breakpoints);
if ($lastBreakpoint && !$lastBreakpoint['media'] && $picturefillMarkup) {
// Generate different image sizes for last breakpoint
$cropArea = $cropVariantCollection->getCropArea($lastBreakpoint['cropVariant']);
$srcset = $this->generateSrcsetImages(
$originalImage,
$referenceWidth,
$lastBreakpoint['srcset'],
$cropArea,
$absoluteUri
);
$srcsetMode = substr(key($srcset), -1); // x or w

// Set srcset attribute for fallback image
$fallbackTag->addAttribute($attributePrefix . 'srcset', $this->generateSrcsetAttribute($srcset));

// Set sizes query for fallback image
if ($srcsetMode == 'w' && $lastBreakpoint['sizes']) {
$fallbackTag->addAttribute('sizes', sprintf($lastBreakpoint['sizes'], $referenceWidth));
}
} else {
// Breakpoint can't be used as fallback
if ($lastBreakpoint) {
array_push($breakpoints, $lastBreakpoint);
}
// Add fallback image source
$fallbackImageUri = $this->imageService->getImageUri($fallbackImage, $absoluteUri);
$fallbackTag->addAttribute($attributePrefix . 'src', $fallbackImageUri);

// Set srcset attribute for fallback image (not src as advised by picturefill)
$fallbackImageUri = $this->imageService->getImageUri($fallbackImage, $absoluteUri);
if ($picturefillMarkup) {
$fallbackTag->addAttribute($attributePrefix . 'srcset', $fallbackImageUri);
} else {
$fallbackTag->addAttribute($attributePrefix . 'src', $fallbackImageUri);
}
// Add lazyload class to fallback image tag
if ($lazyload) {
$existingClass = $fallbackTag->getAttribute('class');
$fallbackTag->addAttribute('class', $existingClass ? $existingClass . ' lazyload' : 'lazyload');
}

// Create placeholder image for lazyloading
if ($lazyload && $placeholderSize) {
$fallbackTag->addAttribute('src', $this->generatePlaceholderImage(
$originalImage,
$placeholderSize,
$cropArea,
null,
$placeholderInline,
$absoluteUri
));
Expand Down Expand Up @@ -349,6 +324,12 @@ public function createSimpleImageTag(
// if lazyload enabled add data- prefix
$attributePrefix = $lazyload ? 'data-' : '';

// Add lazyload class to image tag
if ($lazyload) {
$existingClass = $tag->getAttribute('class');
$tag->addAttribute('class', $existingClass ? $existingClass . ' lazyload' : 'lazyload');
}

// Set image source
$tag->addAttribute($attributePrefix . 'src', $this->imageService->getImageUri($originalImage, $absoluteUri));

Expand Down Expand Up @@ -591,7 +572,7 @@ public function normalizeImageBreakpoints(array $breakpoints): array
*
* @return bool
*/
public function hasIgnoredFileExtension(FileInterface $image, $ignoreFileExtensions = 'svg')
public function hasIgnoredFileExtension(FileInterface $image, $ignoreFileExtensions = 'svg, gif')
{
$ignoreFileExtensions = (is_array($ignoreFileExtensions))
? $ignoreFileExtensions
Expand Down
33 changes: 21 additions & 12 deletions Classes/ViewHelpers/ImageViewHelper.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace SMS\SmsResponsiveImages\ViewHelpers;
namespace Sitegeist\ResponsiveImages\ViewHelpers;

use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection;
use TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException;
use SMS\SmsResponsiveImages\Utility\ResponsiveImagesUtility;
use Sitegeist\ResponsiveImages\Utility\ResponsiveImagesUtility;

class ImageViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\ImageViewHelper
{
Expand Down Expand Up @@ -36,16 +36,27 @@ public function initializeArguments()
'(min-width: %1$dpx) %1$dpx, 100vw'
);
$this->registerArgument('breakpoints', 'array', 'Image breakpoints from responsive design.', false);
$this->registerArgument('picturefill', 'bool', 'Use rendering suggested by picturefill.js', false, true);
$this->registerArgument('lazyload', 'bool', 'Generate markup that supports lazyloading', false, false);
$this->registerArgument('placeholderSize', 'int', 'Size of the placeholder image for lazyloading (0 = disabled)', false, 0);
$this->registerArgument('placeholderInline', 'bool', 'Embed placeholder image for lazyloading inline as data uri', false, false);
$this->registerArgument(
'placeholderSize',
'int',
'Size of the placeholder image for lazyloading (0 = disabled)',
false,
0
);
$this->registerArgument(
'placeholderInline',
'bool',
'Embed placeholder image for lazyloading inline as data uri',
false,
false
);
$this->registerArgument(
'ignoreFileExtensions',
'mixed',
'File extensions that won\'t generate responsive images',
false,
'svg'
'svg, gif'
);
}

Expand All @@ -54,15 +65,15 @@ public function initializeArguments()
*
* @see https://docs.typo3.org/typo3cms/TyposcriptReference/ContentObjects/Image/
*
* @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception
* @throws \TYPO3Fluid\Fluid\Core\Exception
* @return string Rendered tag
*/
public function render()
{
if ((is_null($this->arguments['src']) && is_null($this->arguments['image']))
|| (!is_null($this->arguments['src']) && !is_null($this->arguments['image']))
if (($this->arguments['src'] === '' && is_null($this->arguments['image']))
|| $this->arguments['src'] !== '' && !is_null($this->arguments['image'])
) {
throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception(
throw new \TYPO3Fluid\Fluid\Core\Exception(
'You must either specify a string src or a File object.',
1517766588 // Original code: 1382284106
);
Expand Down Expand Up @@ -116,7 +127,6 @@ public function render()
$focusArea,
null,
$this->tag,
$this->arguments['picturefill'],
$this->arguments['absolute'],
$this->arguments['lazyload'],
$this->arguments['ignoreFileExtensions'],
Expand All @@ -133,7 +143,6 @@ public function render()
$focusArea,
$this->arguments['sizes'],
$this->tag,
$this->arguments['picturefill'],
$this->arguments['absolute'],
$this->arguments['lazyload'],
$this->arguments['ignoreFileExtensions'],
Expand Down
Loading

0 comments on commit 7839c1f

Please sign in to comment.