Download the PHP package offline/responsiveimages-plugin without Composer
On this page you can find all versions of the php package offline/responsiveimages-plugin. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package responsiveimages-plugin
ResponsiveImages Plugin for October CMS
Automatically generate and serve images for your visitor's viewport size without changing your theme!
Features
- Responsive images
- WebP conversion
- Focuspoint
- Inline SVG helper function
Responsive images
How it works
This plugin provides a middleware that adds srcset
and sizes
attributes to all locally served images in your html
response.
It turns this
into this
It automatically creates resized copies of the image and serves the most fitting one to your visitor.
All image copies are saved in your public temp path. Remote file systems are currently untested.
The images are generated on the first page load. Depending on the source image size this may take a few seconds. Subsequent page loads will be faster since the images are only resized once.
Configuration
Three image sizes are created by default: 400, 768 and 1024 pixels.
You can change these values by changing the settings in the backend.
Alternative src
and srcset
attributes
If you want to use an alternative src
attribute you can change this via the backend settings page.
This is useful if you are using a plugin like jQuery.lazyLoad where the image
is initially linked via a data-original
attribute.
If your plugin requires an alternative srcset attribute (like verlok/LazyLoad) this can also be specified via the backend settings.
Global class
attributes
If you want to add a class to every processed image you can configure this via the backend settings.
This is useful if you want to add Bootstrap's img-responsive
class to all images on your website.
Pre-generate images
You can use the php artisan responsive-images:generate
command to pre-generate responsive images. The command uses
October's pages.menuitem.*
events to build a list of all available URLs and pre-generates all images used on these
pages.
Test results
I have tested this plugin on a page with 20 hd wallpapers from pixabay.
Viewport width | Transferred file size |
---|---|
1920 px | 21.8 MB |
1024 px | 3.1 MB |
768 px | 2.0 MB |
400 px | 0.8 MB |
Opt-out of processing
If for any reason you want an img
tag to be completely ignored by this plugin, simply
add the data-responsive="ignore"
attribute to your tag:
Delete resized images
Use the php artisan responsive-images:clear
command to delete all
resized images. The next time a page/image is requested, the resized
copies will be created again.
WebP conversion
This plugin provides an option to serve WebP images if the visiting Browser signals support for it.
Enable the WebP conversion in the backend settings. Enabling this option will add a rule
to your .htaccess
file, that checks for a {filename}.{extension}.webp
image for every request
and serves it to the client, if available.
Console command to convert images to WebP
The plugin includes a handy console command that you can run in a cronjob that iterates through your storage directories and converts images to WebP:
This command requires the cwebp
to be available on your server. You can download it for your OS
and provide the path to the binary using the --converter-path
option.
Conversion errors
You can find a log of failed image conversions in the offline_responsiveimages_inconvertibles
table.
If the conversion for a file failed, it will be logged in this table. The conversion will not be
retried for files that failed before. To force a retry, remove the file from the table table
and run the conversion command again.
Support for other servers than Apache
If you do not use Apache, you have to configure your server to do the following:
- Check if
image/webp
is present in theAccepts
http header - Check if the requested image ends in
jp(e)g
orpng
- Check if the requested image + a
.webp
exists - If it does, serve it
Apache + .htaccess
If you are using Apache with mod_rewrite
enabled, you do not have to do anything manually.
The plugin will patch your .htaccess
file if WebP support gets enabled.
Nginx
If you are using Nginx to serve your October website, you have to modify your server configuration manually.
The following example should give you a good starting point.
Your mime.types
file should additionally list the webp mime type:
Other servers
We did not invest in the proper WebP detection configuration for other server software.
Based on the .htaccess
example above and the webp-detect
repo you should be able to figure out what config is needed.
If you have a working example please add it via a PR to this README!
Custom base directory path
If your application directory is located in a special location, you can set the
RESPONSIVE_IMAGES_BASE_DIR
environment variable to change the source path.
Focuspoint
This feature has two components to it:
Backend
In the backend, the file upload widget is extended with a simple focus point selector.
To enable this extension simply set focuspoint: true
to any fileupload widget in your
plugin's fields.yaml
. This feature is off by default.
Once it is enabled you can click on an uploaded image to select the focus point.
Frontend
You can use the new focus
method on any File
model to get the source to a focus point image.
The focus
method has the exact same API as the thumb
method, you can specify a height
, width
and a mode
.
This call will result in the following HTML:
You can disable the injection of the inline styles via the plugin's backend settings.
If you want to use any of the existing focus point JS libraries you can also define a custom container
that will be place around the image. The focus coordinates can be injected as custom data-*
attributes.
All of these settings are available on the plugin's backend settings page.
Browser-Compatibility
Be aware that object-fit
is not supported in IE without
using a polyfill.
Inlining SVG images
This plugin registers a simple svg
helper function that enables you to inline SVG images from your project.
Using variables
Aside from inlining the SVG itself the helper function will also pass any variables along to the SVG and parse it using October's Twig parser. This means you can easily create dynamic SVGs.
Bug reports
It is very likely that there will be bugs with some specific html markup. If you encounter such a bug, please report it.
Future plans
- Exclude/Include-Filters
- Maybe a component to enable the middleware only on some pages
All versions of responsiveimages-plugin with dependencies
composer/installers Version ~1.0
psr/log Version ^1.1.0|^2.0|^3.0
ext-dom Version *
rosell-dk/webp-convert Version ^2.3