All Projects → brendt → responsive-images

brendt / responsive-images

Licence: other
Generate responsive images to work with the srcset and sizes spec

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to responsive-images

Jekyll picture tag
Easy responsive images for Jekyll.
Stars: ✭ 515 (+871.7%)
Mutual labels:  responsive-images
Twelvety
An Eleventy starter project built to be fast
Stars: ✭ 195 (+267.92%)
Mutual labels:  responsive-images
angular-image-loader
A simple progressive, responsive, lazy image and video loading library for Angular that detects browser size and loads the appropriate image or video only when the element is in viewport. This package requires @thisissoon/angular-inviewport
Stars: ✭ 21 (-60.38%)
Mutual labels:  responsive-images
Grunt Responsive Images
Produce images at different sizes for responsive websites.
Stars: ✭ 726 (+1269.81%)
Mutual labels:  responsive-images
Enfasten
⚡️ Automatically make your site faster with optimized responsive images
Stars: ✭ 56 (+5.66%)
Mutual labels:  responsive-images
Lazysizes
High performance and SEO friendly lazy loader for images (responsive and normal), iframes and more, that detects any visibility changes triggered through user interaction, CSS or JavaScript without configuration.
Stars: ✭ 15,716 (+29552.83%)
Mutual labels:  responsive-images
Cloudinary npm
Cloudinary NPM for node.js integration
Stars: ✭ 450 (+749.06%)
Mutual labels:  responsive-images
gregives.co.uk
Personal site and portfolio of software engineer Greg Ives
Stars: ✭ 43 (-18.87%)
Mutual labels:  responsive-images
Timmy
Advanced image handling for Timber.
Stars: ✭ 146 (+175.47%)
Mutual labels:  responsive-images
guide-to-async-components
📖 Guide To JavaScript Async Components
Stars: ✭ 79 (+49.06%)
Mutual labels:  responsive-images
Vanilla Lazyload
LazyLoad is a lightweight, flexible script that speeds up your website by deferring the loading of your below-the-fold images, backgrounds, videos, iframes and scripts to when they will enter the viewport. Written in plain "vanilla" JavaScript, it leverages IntersectionObserver, supports responsive images and enables native lazy loading.
Stars: ✭ 6,596 (+12345.28%)
Mutual labels:  responsive-images
Sms Responsive Images
This TYPO3 extension provides ViewHelpers and configuration to render valid responsive images based on TYPO3's image cropping tool.
Stars: ✭ 35 (-33.96%)
Mutual labels:  responsive-images
acf-image-aspect-ratio-crop
Image Aspect Ratio Crop field for Advanced Custom Fields
Stars: ✭ 100 (+88.68%)
Mutual labels:  responsive-images
Image Map Resizer
Responsive HTML Image Maps
Stars: ✭ 661 (+1147.17%)
Mutual labels:  responsive-images
axiom
Axiom - A Hugo Theme. GitTip: https://gitcoin.co/tip?username=jhauraw
Stars: ✭ 67 (+26.42%)
Mutual labels:  responsive-images
Gulp Responsive
gulp-responsive generates images at different sizes
Stars: ✭ 509 (+860.38%)
Mutual labels:  responsive-images
Imagecow
PHP library to manipulate and generate responsive images
Stars: ✭ 234 (+341.51%)
Mutual labels:  responsive-images
ember-responsive-image
Automatically generate resized images at build-time, optimized for the responsive web, and using components to render them easily as <picture> elements.
Stars: ✭ 103 (+94.34%)
Mutual labels:  responsive-images
qis
Dynamic image server for web and print
Stars: ✭ 85 (+60.38%)
Mutual labels:  responsive-images
just-responsive-images
WordPress Plugin to support better responsive images with <picture> tag, backgrounds, retina support etc.
Stars: ✭ 47 (-11.32%)
Mutual labels:  responsive-images

Build Status Scrutinizer Code Quality

Responsive Images

Automatically generate responsive images to work with the srcset and sizes spec. (http://responsiveimages.org/)

composer require brendt/responsive-images

Usage

use Brendt\Image\ResponsiveFactory;

$factory = new ResponsiveFactory();
$image = $factory->create('img/image.jpeg');
<img src="<?= $image->src() ?>" 
     srcset="<?= $image->srcset() ?>"/>

This sample would generate something like:

<img src="https://github.com/image.jpeg" 
     srcset="/image-384.jpg 384w,
             /image-768.jpg 768w,
             /image-1152.jpg 1152w,
             /image-1536.jpg 1536w,
             /image.jpg 1920w" />

Configuration

The ResponsiveFactory can take a ResponsiveFactoryConfigurator object which will set the needed parameters. A default configurator DefaultConfigurator is provider out of the box, and uses the following parameters:

[
    'driver'           => 'gd',
    'includeSource'    => true,
    'publicPath'       => './',
    'sourcePath'       => './',
    'rebase'           => false,
    'enableCache'      => false,
    'optimize'         => false,
    'scaler'           => 'filesize',
    'stepModifier'     => 0.5,
    'minFileSize'      => 5000,
    'maxFileSize'      => null,
    'minWidth'         => 300,
    'maxWidth'         => null,
    'sizes'            => [ 1920, 840, 300 ],
    'optimizerOptions' => [],
]

You can override these parameters by providing and array to the DefaultConfigurator, or create a whole new configurator which implements ResponsiveFactoryConfigurator.

$factory = new ResponsiveFactory(new DefaultConfigurator([
    'driver'       => 'imagick',
    'sourcePath'   => './src',
    'publicPath'   => './public',
    'enableCache'  => true,
]));

All configuration options

  • driver: the image driver to use. Defaults to gd. Possible options are gd or imagick.
  • includeSource: whether to include the source image in the srcset. Defaults to true.
  • sourcePath: the path to load image source files. Defaults to ./.
  • publicPath: the path to render image files. Defaults to ./.
  • rebase: ignore the path of the requested image when searching in the source directory. Defaults to false.
  • enableCache: enable or disable image caching. Enabling the cache wont' override existing images. Defaults to false.
  • optimize: enable or disable the use of different optimizers (if installed on the system). Defaults to false.
  • scaler: which scaler algorithm to use. Defaults to filesize. Possible options are filesize, width or sizes.
  • stepModifier: a percentage (between 0 and 1) which is used to create different image sizes. The higher this modifier, the more image variations will be rendered. Defaults to 0.5.
  • minFileSize: the minimum image filesize in bytes. Defaults to 5000B (5KB).
  • maxFileSize: the maximum image filesize in bytes. Defaults to null.
  • minWidth: the minimum image size in pixels. No images with size smaller than this number will be rendered. Defaults to 300 pixels.
  • maxWidth: the maximum image size in pixels. No images with size smaller than this number will be rendered. Defaults to null.
  • sizes: this parameter is used when the sizes scaler is enabled. This scaler will generate a fixed set of sizes, based on this array. The expected values are the widths of the generated images. Defaults to [] (empty array).
  • optimizerOptions: options to pass to the image optimizer library. See https://github.com/psliwa/image-optimizer for more information.

Paths

The sourcePath parameter is used to define where image source files are located. In case of the first example and above configuration, the image file should be saved in ./src/img/image.jpeg.

The publicPath parameter is used to save rendered images into. This path should be the public directory of your website. The above example would render images into ./public/img/image.jpeg.

Path rebasing

When the rebase option is enabled, source file lookup will differ: only the filename is used to search the file in the source directory. An example would be the following.

// Without rebase

$options = [
    'sourcePath' => './src/images',
    'publicPath' => './public',
];

$image = $factory->create('/img/responsive/image.jpeg');

// Source file is searched in './src/images/img/responsive/image.jpeg' 
// Public files are saved in './public/img/responsive/image-x.jpg'
// With rebase

$options = [
    'sourcePath' => './src/images',
    'publicPath' => './public',
    'rebase'     => true,
];

$image = $factory->create('/img/responsive/image.jpeg');

// Source file is searched in './src/images/image.jpeg'  
// Public files are saved in './public/img/responsive/image-x.jpg'
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].