2017 © Pedro Peláez
 

php-extension html-picture-element

Generates picture html tag with different types of sources

image

deitsolutions/html-picture-element

Generates picture html tag with different types of sources

  • Monday, May 28, 2018
  • by deitsolutions
  • Repository
  • 2 Watchers
  • 0 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Description

A simple PHP class to generate the HTML *picture* element with different source types supported. It could be used for optimization of image rendering depending on the browser supporting one or another image format., (*1)

Installation

The preferred way to install this extension is through composer., (*2)

Place composer.phar file in the same directory with composer.json file and run, (*3)

$ php composer.phar require almeyda/html-picture-element "*"

or add, (*4)

{
    ...
    "require": {
        ...
        "almeyda/html-picture-element": "dev-master"
        ...
    }
    ...
}

to the "require" section of your composer.json file and run, (*5)

$ php composer.phar update

Usage

\almeyda\htmlpicture\src\HtmlPicture::get($src, $attributes, $sourceTypes);

Where: - src - path to main image - attributes - "<image"> tag attributes - sourceTypes - array of the image types to be collected into picture sources, (*6)

Example of usage:

\almeyda\htmlpicture\src\HtmlPicture::get('path/to/image.png', ['alt' => 'Image alt'], ['webp', 'jp2', 'jpx']),

This produces an output like, (*7)

<picture>
    <source srcset="path/to/image.webp?v=1527278990" type="image/webp">
    <source srcset="path/to/image.jp2?v=1527278990" type="image/jp2">
    <source srcset="path/to/image.jpx?v=1527278990" type="image/jpx">
    <img src="path/to/image.png?v=1527278990" alt="Image alt">
</picture>

You can define image types to be collected and rendered into picture tag once using a method setSouceTypes, (*8)

\almeyda\htmlpicture\src\HtmlPicture::setSouceTypes(['webp', 'jp2', 'jpx']);

...

\almeyda\htmlpicture\src\HtmlPicture::get('path/to/image1.png'),

\almeyda\htmlpicture\src\HtmlPicture::get('path/to/image2.png'),

The Versions

28/05 2018

dev-master

9999999-dev https://github.com/deitsolutions/html-picture-element

Generates picture html tag with different types of sources

  Sources   Download

BSD-3-Clause

The Requires

 

php html element picture