Giter Site home page Giter Site logo

alexanderschnitzler / fluid-styled-responsive-images Goto Github PK

View Code? Open in Web Editor NEW
27.0 9.0 16.0 878 KB

Enables creation of responsive images for fluid styled content elements.

Home Page: http://typo3.org/extensions/repository/view/fluid_styled_responsive_images

PHP 97.77% TypeScript 2.23%
fluid typo3-cms responsive-images typo3 typo3-cms-extension

fluid-styled-responsive-images's Introduction

TYPO3 CMS Extension "fluid_styled_responsive_images"

Build Status Codecov

Total Downloads Latest Stable Version Latest Unstable Version License

This project aims to provide an image-rendering process that will render responsive images with fluid, where the assumption is made, that TYPO3 CMS doesn't provide a mechanism out of the box for fluid templates while one is able to do it with TypoScript.

Installation

  • Install via composer using the current stable release and track new stable releases: composer require schnitzler/fluid-styled-responsive-images:"^10.2" and enable the extension through the extension manager / your preferred mechanism
  • Use the current development version by running composer require schnitzler/fluid-styled-responsive-images:"dev-master" in your composer.json file, run composer update
  • Clone the current development version to your typo3conf/ext directory (ex. cd typo3conf/ext && rm -Rf fluid_styled_responsive_images && git clone https://github.com/alexanderschnitzler/fluid-styled-responsive-images.git fluid_styled_responsive_images)

Configuration

The extension is configured through TypoScript, like most parts of your site are. Include the static TypoScript of the extension and then begin with the Configuration through your own TypoScript setup.

The ImageRenderer currently supports the [srcset](srcset specification) and rendering as data-attributes, which is to make custom rendering with javascript easier.

Minimal, empty configuration:

tt_content.textmedia.settings.responsive_image_rendering {
    layoutKey = srcset

    sourceCollection {
        # Please write your own sourceCollection configuration
    }
}

Mode srcset

A sourceCollection entry is a TypoScript hash. It can contain the following indices:

key description example
width The target size of the generated image. Supports modifications like m & c 1200c (crops the image to 1200px)
srcset a string describing the condition under which the image is displayed 1200w (1200px viewports)
dataKey a name for the generated data-attribute desktop
sizes [optional] a media query with custom styles to be applied (min-width: 1200px) 1170px

For more precise descriptions, please check out the html img element specification on srcset.

Configuration Example

tt_content.textmedia {
    settings {
        responsive_image_rendering {
            layoutKey = srcset

            sourceCollection {
                10 {
                    dataKey = desktop
                    width = 1260m
                    srcset = 1260w
                }

                20 {
                    dataKey = table
                    width = 960m
                    srcset = 960w
                }

                30 {
                    dataKey = tablet-small
                    width = 720m
                    srcset = 720w
                }

                40 {
                    dataKey = medium
                    width = 640m
                    srcset = 640w
                }

                50 {
                    dataKey = medium-phone
                    width = 360m
                    srcset = 360w
                }

                60 {
                    dataKey = small
                    width = 320m
                    srcset = 320w
                }
            }
        }
    }
}

Usage

After installation and configuration, the output of the <f:media> viewhelper uses the logic this extension supplies for images and renders the image.

Inner workings

  1. a custom image renderer is registered
  2. when the RendererRegistry is asked for a renderer suitable for the current mimetype, the renderer proposes itself if one of the known image mimetypes is matched
  3. the renderer reads the current TypoScript and merges it with global extension configuration like the enableSmallDefaultImage setting
  4. the renderer then calculates the needed sizes and returns a ready-made img-tag

Extending fluid_styled_responsive_images

Since fluid_styled_content is used, much of the output in TYPO3 CMS can be adjusted.

Example of registering custom templates and adjusting images in collaboration with the GalleryProcessor in fluid_styled_content to provide precise rendering with Bootstrap 3 based templates: websightgmbh/ws-texmedia-bootstrap.

License

GPL-2.0+

fluid-styled-responsive-images's People

Contributors

alexanderschnitzler avatar cedricziel avatar fazzyx avatar whiteroom avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fluid-styled-responsive-images's Issues

Wrong image width

As the GalleryProcessor is executed before the ImageRenderer, the given width is defined by the typoscript constant styles.content.textmedia.maxWInText that is by default set to 600. This compromises the idea of responsive images, where huge images are necessary for the creation of retina images.

The solution is not to rely on the given width, but use the width of the actual image record.

Do not create larger images than possible

If the native width of an original image is less than the desired width of a srcset definition the creation of that image must be avoided because else a low quality image with a higher width than the original one will be created. This only causes images with a bigger size but less quality then the default one.

Alt & title arguments of the media viewhelper are not respected

Hi,

it seems that the alt and the title arguments of the media viewhelper are totally ignored in the rendered image tags. We use the extension in a multilanguage project, here the title and alt of the root language is used, no matter what's written in the viewhelper.

I think of two possible solutions:

  • Add title and alt to the $genericTagAttributes in ImageRendererConfiguration,
  • or read them directly from the $options in the buildImageTag function...

In both cases it's not needed anymore to get the properties from the FileInterface...

What do you think?

Bregs
Tilman

Height of default image processing must be ignored

Example: An image is 1024*768 but in a textmedia element the width of that element is set to 100px, the height will be adjusted accordingly, resulting in wrong image widths for the processed responsive images.

srcset-Rendering without "width" doesn't work correctly

When is setup srcsetCandidates widthout defining a width, css_styled_content uses the width a user enters in the appearance field in the content element.
That is what i would expect, as i use this to render images to certain size and provide a high density srcset for high dpi displays.

My setup in css_styled_content looks like this:
tt_content.image.20.1.sourceCollection >
tt_content.image.20.1.sourceCollection {
normal.srcsetCandidate = 1x
normal.quality = 65
retina.srcsetCandidate = 2x
retina.pixelDensity = 2
retina.quality = 30
}
tt_content.image.20.1.layout.srcset {
element = <img srcset="###SOURCECOLLECTION###" ###PARAMS### ###ALTPARAMS### ###SELFCLOSINGTAGSLASH###>
source = |*|###SRC### ###SRCSETCANDIDATE###,|*|###SRC### ###SRCSETCANDIDATE###
}

When i adapt that for fluid_styled_responsive_images the extensions uses 360px width for each rendered image (hardcoded in "ImageRenderer.php" line 134) but doesn't use the width entered in the appearance field:
tt_content.textmedia.settings.responsive_image_rendering.sourceCollection {
normal.srcsetCandidate = 1x
normal.quality = 65
retina.srcsetCandidate = 2x
retina.pixelDensity = 2
retina.quality = 30
}
tt_content.textmedia.settings.responsive_image_rendering.layout.srcset {
element = <img srcset="###SOURCECOLLECTION###" ###PARAMS### ###ALTPARAMS### ###SELFCLOSINGTAGSLASH###>
source = |*|###SRC### ###SRCSETCANDIDATE###,|*|###SRC### ###SRCSETCANDIDATE###
}

So there is no possibility to allow a user to set sizes for images in the backend while having retina images.

The keyword 'auto' for config.absRefPrefix leads to a corrupt tag

Since TYPO3 7.1 you have the possibility to set absRefPrefix to auto, which will lead to a corrupt src-tag: https://docs.typo3.org/typo3cms/TyposcriptReference/Setup/Config/Index.html#absrefprefix

The problem is that absRefPrefix is inserted without further processing in Schnitzler\FluidStyledResponsiveImages\Resource\Rendering\ImageRenderer:

$url = $this->absRefPrefix . $processedFile->getPublicUrl();

As you can see, TYPO3 checks for the keyword auto in TYPO3\CMS\Frontend\Page\PageGenerator:

// calculate the absolute path prefix
if (!empty($tsfe->config['config']['absRefPrefix'])) {
  $absRefPrefix = trim($tsfe->config['config']['absRefPrefix']);
  if ($absRefPrefix === 'auto') {
    $tsfe->absRefPrefix = GeneralUtility::getIndpEnv('TYPO3_SITE_PATH');
  } else {
    $tsfe->absRefPrefix = $absRefPrefix;
  }
} else {
  $tsfe->absRefPrefix = '';
}

Perhaps the same check should be applied to Schnitzler\FluidStyledResponsiveImages\Resource\Rendering\ImageRenderer.

Fluid f:image and srcset

Hello,

when I use the MASK Extension and within a template file the f:image view helper there is no srcset render.

Can I activate it there or it is not possible ?

Greetings.

f:media within Mask

Hello,

I think, I should open a new ticket for this problem.

When I use the f:media view helper within a mask element I don't get the sourceset attribute to my images.

Typoscript configuration:

tt_content {
    textmedia {
        settings {
            image_classes = {$styles.content.textmedia.imageClasses}
            responsive_image_rendering {
                layoutKey = srcset

                # Default Breakpoints
                sourceCollection {
                    xl {
                        width = 1200
                        srcset = 1200w
                    }

                    lg {
                        width = 992
                        srcset = 992w
                    }

                    md {
                        width = 768
                        srcset = 768w
                    }

                    sm {
                        width = 480
                        srcset = 480w
                    }

                    xs {
                        width = 320
                        srcset = 320w
                        sizes = auto
                    }
                }
            }

            origo < tx_origo
        }
    }
}

Within the Text & Media Element all work correct.

In my template I have the following loading order:

  1. FSCI
  2. Mask
  3. My Extension who contains the mask layouts

I hope, u can help me.

no responsive image is generated

Hello,

it doesn't work (fluid_styled_responsive_images Version 1.1.1).

I've included the follwing static templates:
Content Elements (fluid_styled_content)
Content Elements CSS (optional) (fluid_styled_content)
Fluid Styled Responsive Images (fluid_styled_responsive_images)

into my TYPO3 7.6.6.

TypoScript-Setup:

tt_content.textmedia.settings.responsive_image_rendering.sourceCollection {
  small {
    width = 360m
    srcset = 360w
    sizes = 100vw
  }
  medium {
   width = 720m
    srcset = 720w
    sizes = 100vw
  }
  large {
    width = 940m
    srcset = 940w
    sizes = 100vw
  }
  bigger {
    width = 1140m
    srcset = 1140w
    sizes = 100vw
  }
}

No image is rendered to the srcset-attribute in the textmedia-elemtent:

<div class="ce-textpic ce-left ce-intext">
    <div class="ce-gallery" data-ce-columns="1" data-ce-images="1">
        <div class="ce-row">
            <div class="ce-column">
                <figure>    
                    <img sizes="100vw, 100vw, 100vw, 100vw" title="Titel Dateiebene" alt="Alternativer Text Dateiebene" src="fileadmin/_processed_/1/8/csm_DSC02028_067a75714b.jpg">
                    <figcaption>
                        Beschreibung Dateiebene
                    </figcaption>
                </figure>
[...]

If I set the width-settings to a comment,:

tt_content.textmedia.settings.responsive_image_rendering.sourceCollection {
  small {
#    width = 360m
    srcset = 360w
    sizes = 100vw
  }
  medium {
#   width = 720m
    srcset = 720w
    sizes = 100vw
  }
  large {
#    width = 940m
    srcset = 940w
    sizes = 100vw
  }
  bigger {
#    width = 1140m
    srcset = 1140w
    sizes = 100vw
  }
}

I get the following img-tag with srcset-attribute, but again no scaled image is generated:

[...]
<img sizes="100vw, 100vw, 100vw, 100vw" srcset="fileadmin/user_upload/images/DSC02028.JPG 360w, fileadmin/user_upload/images/DSC02028.JPG 720w, fileadmin/user_upload/images/DSC02028.JPG 940w, fileadmin/user_upload/images/DSC02028.JPG 1140w" title="Titel Dateiebene" alt="Alternativer Text Dateiebene" src="fileadmin/_processed_/1/8/csm_DSC02028_067a75714b.jpg">
[...]

New release please

I'd be glad if you could release a new version with the changes for the attributes.

Cheers!

Option to enable rendering of original size as biggest size

I configure the size of images like this:

tt_content.textmedia.settings.responsive_image_rendering.sourceCollection {  
    xs {
        width = 320m
        srcset = 320w
        sizes = calc(100vw - 30px)
    }
    sm {
        width = 514m
        srcset = 514w
        sizes = (min-width: 544px) 514px
    }

    md {
        width = 738m
        srcset = 738w
        sizes = (min-width: 768px) 738px        
    }

    lg {
        width = 962m
        srcset = 962w
        sizes = (min-width: 992px) 962px        
    }

    xl {
        width = 1170m
        srcset = 1170w
        sizes = (min-width: 1200px) 1170px
    }

    xlretina {
        width = 2340m
        srcset = 2340w
        quality = 30
    }       
}

When i insert an image with maybe 1000px, all sizes below "xl" are rendered. But not the original size of the image. Therefore for example screenshots images are not rendered in their original size and appear blurred.
Wouldn't it be great to have an option to enable rendering in original size if it is smaller that the biggest defined size or maybe that a certain size (which a can set to my biggest defined size).

set alt and title from merged properties

$this->tagBuilder->addAttribute('alt', $file->getProperty('alternative'));
$this->tagBuilder->addAttribute('title', $file->getProperty('title'));

Set alt and title from filereference too.

Make default image with 360px width optional

The idea of a small default image is still a good solution when working with polyfills, but it does not allow to render images smaller than 360px properly, like icons.

Therefore the default image should be optional, but enabled by default to not be breaking.

8LTS: Don't touch TCA in ext_tables.php

TCA changes within ext_tables.php can be moved to Configuration/TCA since core 6.2

Please update:

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile(
'fluid_styled_responsive_images',
'Configuration/TypoScript',
'Fluid Styled Responsive Images'
);

has to go to /Configuration/TCA/Overrides/sys_template.php

LTS 8: Backend image editor crop settings are ignored

Hi.

I got the folloing behaviour:
Using the actual git-version with TYPO3 LTS 8.7.1 the image rendering process ignores the crop settings of the TYPO3 internal image editor.
This happened directly after the installation of the extension - before Static Templates an TS Setup are added. Adding Templates and TS Setup does not change this behaviour.

If the extension is uninstalled image crop settings are respected again.


Hint after testing:

TYPO3 8.7.1 generates defaultProcessConfiguration like this:

Array ( [width] => 360m [crop] => {"default":{"cropArea":{"height":0.376,"width":0.503,"x":0.291,"y":0.6066666666666667},"selectedRatio":"16:9","focusArea":null}} )

TYPO3 7 LTS generates defaultProcessConfiguration like this - taken from a different project:

Array ( [width] => 360m [crop] => {"x":1280,"y":960.3583426651736,"width":1280,"height":960.3429796355841,"rotate":0} )

For testing i replaced the LTS 8 defaultProcessingConfiguration with the LTS 7 test confguration ind the Class Schnitzler\FluidStyledResponsiveImages\Resource\Rendering\Imagerenderer and it worked.
image

Hope this helps.

Aus einem 25 KB Bild wird eine über 1 MB große Datei

Die original Bilddateien sind Web optimiert und sehr klein, leider werden in der mobilen Ansicht auf einmal echte Brocken bereit gestellt.

Google PageSpeed meckert hier mit recht an:

Bilder optimieren
Durch eine korrekte Formatierung und Komprimierung von Bildern können viele Datenbytes gespart werden.
Optimieren Sie die folgenden Bilder, um ihre Größe um 5 MB (90 %) zu reduzieren.

Durch die Komprimierung und Größenanpassung von http://www.digitale-fotografien.com/…2015_auszeichnung_200x292_70b788cac4.png könnten 1,1 MB (83 %) eingespart werden.
Durch die Komprimierung und Größenanpassung von http://www.digitale-fotografien.com/…/csm_Proven-Expert-Siegel_27823161a5.png könnten 1.001,7 KB (94 %) eingespart werden.
Durch die Komprimierung und Größenanpassung von http://www.digitale-fotografien.com/…ochzeitsfotograf-in-Essen_275d6c8271.jpg könnten 551,3 KB (97 %) eingespart werden.
Durch die Komprimierung und Größenanpassung von http://www.digitale-fotografien.com/…er-Fotoshooting-im-Studio_89670606db.jpg könnten 542,9 KB (98 %) eingespart werden.
Durch die Komprimierung und Größenanpassung von http://www.digitale-fotografien.com/…2016_auszeichnung_200x349_7e8bcb72f2.png könnten 525,8 KB (76 %) eingespart werden.
Durch die Komprimierung und Größenanpassung von http://www.digitale-fotografien.com/…-Bewerbungsfotos-in-Essen_f31328a687.jpg könnten 314,1 KB (97 %) eingespart werden.
Durch die Komprimierung und Größenanpassung von http://www.digitale-fotografien.com/…uesseldorf-Dortmund-Koeln_6a89fac050.jpg könnten 284,9 KB (98 %) eingespart werden.
Durch die Komprimierung und Größenanpassung von http://www.digitale-fotografien.com/…Teaser-Businessfotografie_c1c1235add.jpg könnten 260,4 KB (98 %) eingespart werden.
Durch die Komprimierung und Größenanpassung von http://www.digitale-fotografien.com/…0/8/csm_Teaser-Imagefilme_a500b45553.jpg könnten 231,5 KB (98 %) eingespart werden.
Durch die Komprimierung und Größenanpassung von http://www.digitale-fotografien.com/…sm_Teaser-Eventfotografie_20c281191d.jpg könnten 224,7 KB (98 %) eingespart werden.
Durch die Komprimierung von http://www.digitale-fotografien.com/…otografie-Security-2016-1_d46482fa20.jpg könnten 2,8 KB (39 %) eingespart werden.
Durch die Komprimierung von http://www.digitale-fotografien.com/…1/csm_ETB-Wohnbau-Baskets_670908b863.jpg könnten 944 Byte (17 %) eingespart werden.
Durch die Komprimierung von http://www.digitale-fotografien.com/…logo-mitglied-im-dpv-grau_1486dd3323.jpg könnten 727 Byte (12 %) eingespart werden.

What i am missing?

i have installed the extension and included the static template after fluid styled content.

tt_content.textmedia.settings.responsive_image_rendering.sourceCollection { medium { width = 720m srcset = 720w sizes = 100vw } large { width = 940m srcset = 940w sizes = 100vw } bigger { width = 1140m srcset = 1140w sizes = 100vw } }
this is my testcode. But my images are missing the srcset attribute?
I am missing something?

edit:
if i make a var_dump of $this in function buildImageTag then i see that srcset is empty. But you can see my typoscript. srcset ist set.

if i write a throw exception instead of continue in processSourceCollection, then i get a:
RuntimeException thrown in file
ext/fluid_styled_responsive_images/Classes/Resource/Rendering/ImageRenderer.php in line 191.
if ((int)$sourceCollection['width'] > (int)$this->defaultWidth) {

What does it mean?
How is the width (default width) calculated?

only works if i set
styles.content.textmedia.maxW = 10000 styles.content.textmedia.maxWInText = 10000

Image file size PNG

Hi,

How can this be fixed: I uploaded a png file in text & media. The original file was optimized to 50 kb. Now when it gets processed with f-s-r-images it has 113 kb. Google pagespeed was bringing up this issue. What do I have to do, that the image size isn't getting bigger?

Thx, Florian

use of this extension?

Hi, I installed the extension and included static template into my main template. When I take a look at the rendered html code I don't see any difference without the extension. As rendering definition I'm using fluid_styled_content. What doing I'm wrong?

Problem with jpg image size of the src image

Hi Alex,

perhaps I miss something, but when installing your extension, I have a problem with the jpg images in the img-src. They are included in the original size I uploaded them - frontend and backend. PNG is fine. Anyway as you mentioned, actually the src should be 360px. Any suggestions, what could cause this?
Additional info: jpg are rendered smaller, when I use them in a text/media element with text. Just an image without text, it's getting that large.
Page jpg image without text: https://www.sineos.de/
Page jpg image with text: https://www.sineos.de/loesungen/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.