From 2a44103ba3ca8b271a68d05a88f72d9732350a40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Sun, 26 Dec 2021 20:04:12 +0100 Subject: [PATCH] Add webp image processing --- .ddev/config.yaml | 2 +- composer.json | 1 + composer.lock | 58 +++++++++++++++- public/.htaccess | 164 +++------------------------------------------- 4 files changed, 68 insertions(+), 157 deletions(-) diff --git a/.ddev/config.yaml b/.ddev/config.yaml index a2c3340b..28d3ee98 100644 --- a/.ddev/config.yaml +++ b/.ddev/config.yaml @@ -23,7 +23,7 @@ hooks: - exec: sudo chmod 600 /home/fromme/.ssh/authorized_keys - exec: sudo service ssh start omit_containers: [dba] -webimage_extra_packages: [ssh] +webimage_extra_packages: [ssh,webp] use_dns_when_possible: true timezone: Europe/Berlin composer_version: "2" diff --git a/composer.json b/composer.json index afe9c999..64707a61 100644 --- a/composer.json +++ b/composer.json @@ -19,6 +19,7 @@ "kigkonsult/icalcreator": "^2.29", "league/csv": "^9.2", "league/period": "^4.9", + "plan2net/webp": "^4.1", "ssch/typo3-encore": "^3.0", "symfony/http-client": "^4.3", "symfony/options-resolver": "^4.2", diff --git a/composer.lock b/composer.lock index 96f19889..25fcdeb0 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "097da910258a46f5f1bcc5aeee693ca4", + "content-hash": "bec75d11ac7a00055213b40b9e6fd574", "packages": [ { "name": "b13/container", @@ -2904,6 +2904,62 @@ ], "time": "2021-12-25T07:07:57+00:00" }, + { + "name": "plan2net/webp", + "version": "4.1.0", + "source": { + "type": "git", + "url": "https://github.com/plan2net/webp.git", + "reference": "0c60cdf38b6fe335e1a1813b8e3cc8ac1cd8b3be" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/plan2net/webp/zipball/0c60cdf38b6fe335e1a1813b8e3cc8ac1cd8b3be", + "reference": "0c60cdf38b6fe335e1a1813b8e3cc8ac1cd8b3be", + "shasum": "" + }, + "require": { + "ext-gd": "*", + "php": ">=7.2.0", + "typo3/cms-core": "^10.4|^11.5" + }, + "type": "typo3-cms-extension", + "extra": { + "typo3/cms": { + "extension-key": "webp" + } + }, + "autoload": { + "psr-4": { + "Plan2net\\Webp\\": "Classes/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-3.0" + ], + "authors": [ + { + "name": "Wolfgang Klinger", + "role": "Lead Developer" + }, + { + "name": "Martin Kutschker", + "role": "reStructuredText Documentation" + }, + { + "name": "Team Wonderland", + "role": "Support and review" + } + ], + "description": "Creates WebP copies for images (TYPO3 CMS)", + "homepage": "https://www.plan2.net/", + "support": { + "issues": "https://github.com/plan2net/webp/issues", + "source": "https://github.com/plan2net/webp/tree/4.1.0" + }, + "time": "2021-11-08T18:03:00+00:00" + }, { "name": "psr/cache", "version": "1.0.1", diff --git a/public/.htaccess b/public/.htaccess index e4c320b9..bad8754c 100644 --- a/public/.htaccess +++ b/public/.htaccess @@ -15,6 +15,8 @@ AddEncoding gzip .gzip +AddType image/webp .webp + # Force compression for mangled `Accept-Encoding` request headers @@ -221,6 +223,9 @@ AddDefaultCharset utf-8 Header set Access-Control-Allow-Origin "*" + + Header append Vary Accept + ### End: Cross Origin ### @@ -277,161 +282,10 @@ AddDefaultCharset utf-8 # NOTE: Add your additional local storages here RewriteRule ^(?:typo3/|fileadmin/|typo3conf/|typo3temp/|uploads/|favicon\.ico) - [L] - ### Begin: StaticFileCache (preparation) #### - - # Document root configuration - RewriteRule .* - [E=SFC_ROOT:%{DOCUMENT_ROOT}] - - # Cleanup URI - RewriteCond %{REQUEST_URI} ^.*$ - RewriteRule .* - [E=SFC_URI:/%{REQUEST_URI}] - RewriteCond %{REQUEST_URI} ^/.*$ - RewriteRule .* - [E=SFC_URI:%{REQUEST_URI}] - RewriteCond %{REQUEST_URI} ^/?$ - RewriteRule .* - [E=SFC_URI:/] - - # Cleanup HOST - RewriteCond %{HTTP_HOST} ^([^:]+)(:[0-9]+)?$ - RewriteRule .* - [E=SFC_HOST:%1] - - # Disable cache for EXT:solr indexing requests - RewriteCond %{HTTP:X-Tx-Solr-Iq} .+ - RewriteRule .* - [E=SFC_HOST:invalid-host] - - # Get scheme - RewriteRule .* - [E=SFC_PROTOCOL:http] - RewriteCond %{SERVER_PORT} ^443$ [OR] - RewriteCond %{HTTP:X-Forwarded-Proto} https - RewriteRule .* - [E=SFC_PROTOCOL:https] - - # Get port - RewriteRule .* - [E=SFC_PORT:80] - RewriteCond %{ENV:SFC_PROTOCOL} ^https$ [NC] - RewriteRule .* - [E=SFC_PORT:443] - RewriteCond %{SERVER_PORT} ^[0-9]+$ - RewriteRule .* - [E=SFC_PORT:%{SERVER_PORT}] - RewriteCond %{HTTP:X-Forwarded-Port} ^[0-9]+$ - RewriteRule .* - [E=SFC_PORT:%{HTTP:X-Forwarded-Port}] - - # Full path for redirect - RewriteRule .* - [E=SFC_FULLPATH:typo3temp/tx_staticfilecache/%{ENV:SFC_PROTOCOL}_%{ENV:SFC_HOST}_%{ENV:SFC_PORT}%{ENV:SFC_URI}/index] - - # Extension (Order: br, gzip, default) - RewriteRule .* - [E=SFC_EXT:] - RewriteCond %{HTTP:Accept-Encoding} br [NC] - RewriteRule .* - [E=SFC_EXT:.br] - RewriteCond %{ENV:SFC_ROOT}/%{ENV:SFC_FULLPATH}%{ENV:SFC_EXT} !-f - RewriteRule .* - [E=SFC_EXT:] - RewriteCond %{ENV:SFC_EXT} ^$ - RewriteCond %{HTTP:Accept-Encoding} gzip [NC] - RewriteRule .* - [E=SFC_EXT:.gz] - RewriteCond %{ENV:SFC_EXT} ^\.gz$ - RewriteCond %{ENV:SFC_ROOT}/%{ENV:SFC_FULLPATH}%{ENV:SFC_EXT} !-f - RewriteRule .* - [E=SFC_EXT:] - - # Write Extension to SFC_FULLPATH - RewriteRule .* - [E=SFC_FULLPATH:%{ENV:SFC_FULLPATH}%{ENV:SFC_EXT}] - - ### Begin: StaticFileCache (main) #### - - # We only redirect URI's without query strings - RewriteCond %{QUERY_STRING} ^$ - - # It only makes sense to do the other checks if a static file actually exists. - RewriteCond %{ENV:SFC_ROOT}/%{ENV:SFC_FULLPATH} -f - - # NO frontend or backend user is logged in. Logged in users may see different - # information than anonymous users. But the anonymous version is cached. So - # don't show the anonymous version to logged in users. - RewriteCond %{HTTP_COOKIE} !staticfilecache [NC] - - # We only redirect GET requests - RewriteCond %{REQUEST_METHOD} GET - - # Rewrite the request to the static file. - RewriteRule .* %{ENV:SFC_ROOT}/%{ENV:SFC_FULLPATH} [L] - - # Do not allow direct call the cache entries - RewriteCond %{ENV:SFC_URI} ^/typo3temp/tx_staticfilecache/.* - RewriteCond %{ENV:REDIRECT_STATUS} ^$ - RewriteRule .* - [F,L] - - # Handle application cache - RewriteCond %{REQUEST_FILENAME} !-f - RewriteCond %{REQUEST_FILENAME} !-d - RewriteCond %{REQUEST_FILENAME} !-l - RewriteRule ^.*\.sfc$ %{ENV:CWD}index.php?eID=sfc_manifest [QSA,L] - - ### Begin: StaticFileCache (options) #### - - # Set proper content type and encoding for gzipped html. - - SetEnv no-gzip 1 - SetEnv no-brotli 1 - - Header set Content-Encoding gzip - - - - SetEnv no-gzip 1 - SetEnv no-brotli 1 - - Header set Content-Encoding gzip - - - - SetEnv no-gzip 1 - SetEnv no-brotli 1 - - Header set Content-Encoding br - - - - # if there are same problems with ForceType, please try the AddType alternative - # Set proper content type gzipped html - - ForceType text/html - # AddType "text/html" .gzip - - - ForceType text/xml - # AddType "text/xml" .gzip - - - ForceType text/xml - # AddType "text/xml" .gzip - - - ForceType text/html - # AddType "text/html" .gz - - - ForceType text/xml - # AddType "text/xml" .gz - - - ForceType text/xml - # AddType "text/xml" .gz - - - ForceType text/html - # AddType "text/html" .br - - - ForceType text/xml - # AddType "text/xml" .br - - - ForceType text/xml - # AddType "text/xml" .br - - - # Avoid .br files being delivered with Content-Language: br headers - - RemoveLanguage .br - - - ### End: StaticFileCache ### + RewriteCond %{HTTP_ACCEPT} image/webp + RewriteCond %{REQUEST_FILENAME} (.*)\.(png|gif|jpe?g)$ + RewriteCond %{REQUEST_FILENAME}\.webp -f + RewriteRule ^ %{REQUEST_FILENAME}\.webp [L,T=image/webp] # If the file/symlink/directory does not exist => Redirect to index.php. # For httpd.conf, you need to prefix each '%{REQUEST_FILENAME}' with '%{DOCUMENT_ROOT}'.