Download the PHP package waughj/html-image without Composer

On this page you can find all versions of the php package waughj/html-image. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package html-image

HTML Image

Simple class for encapsulating image info and autogenerating the HTML for it.

The 1st mandatory argument to pass into the constructor is the src.

2nd optional argument is a FileLoader instance that will make loading images from certain URLs & adding a cache-corruption-fixing version parameter to it. For no FileLoader, pass in null. For mo' info on FileLoader, visit https://github.com/waughjai/file-loader.

3rd is an optional hash map o' attributes.

If no alt attribute is passed in, an empty alt attribute will automatically be added to the image's HTML, as per proper HTML protocol.

Example

use WaughJ\HTMLImage\HTMLImage;
use WaughJ\FileLoader\FileLoader;

$image = new HTMLImage
(
    'image.png',
    new FileLoader([ 'directory-url' => 'https://www.example.com' ]),
    [
        'class' => 'center-img ornate',
        'width' => '600',
        'height' => '400'
    ]
);
$image->print();

Will output <img src="https://www.example.com/image.png" class="center-img ornate" width="600" height="400" />

echo $image->getSource();

Will output https://www.example.com/image.png

Changing Attributes o' Already-Existing Instances

You can also set attributes or add classes to an already-created image using the "setAttribute" & "addToClass" methods:

$image = new HTMLImage
(
    new FileLoader([ 'directory-url' => 'https://www.example.com' ]),
    'image.png',
    [
        'class' => 'center-img ornate',
        'width' => '600',
        'height' => '400'
    ]
);
$image = $image->addToClass( 'new-image' );
$image = $image->setAttribute( 'id', 'first-image' )
$image->print();

Will output <img src="https://www.example.com/image.png" class="center-img ornate new-image" id="first-image" width="600" height="400" />

Note that "setAttribute" & "addToClass" do not directly change object, which is immutable, but return a clone o' the image with the changes. Thus, if you want to change an object, you must set the object equal to the output o' the method call: $image = $image->setAttribute( 'id', 'first-image' ). Just $image->setAttribute( 'id', 'first-image' ) won't do anything.

Responsive Images

HTMLImage makes setting srcset & sizes for responsive images easier & mo’ convenient.

For instance, if srcset is set, but not sizes, the constructor will automatically generate a sizes attribute based on how srcset is set, which will regenerate if srcset is changed later, but will ne’er o’erride manually-set sizes.

Example:

use WaughJ\HTMLImage\HTMLImage;

$image = new HTMLImage
(
    "demo.png",
    null,
    [ 'srcset' => 'demo-300x300.png 300w, demo-800x500.png 800w, demo.png 1280w' ]
);

// Will output “<img src="demo.png" srcset="demo-300x300.png 300w, demo-800x500.png 800w, demo.png 1280w" sizes="(max-width: 300px) 300px, (max-width: 800px) 800px, 1280px" alt="" />”
$image->print();

HTMLImage can also recognize a shorthand version o’ srcset using : as delimiter following the following pattern:

[$path].[$extension]:[$width]x[$height],[$width]x[$height][…]

For each comma-delimited size, height is optional. Not providing a height will simply use the base filename as the full filename & will just use the width as the width tag that goes after the filename.

For example, to print out the same content as the previous example, you can type out ’stead:

use WaughJ\HTMLImage\HTMLImage;

$image = new HTMLImage
(
    "demo.png",
    null,
    [ 'srcset' => 'demo.png:300x300,800x500,1280' ]
);

// Will output “<img src="demo.png" srcset="demo-300x300.png 300w, demo-800x500.png 800w, demo.png 1280w" sizes="(max-width: 300px) 300px, (max-width: 800px) 800px, 1280px" alt="" />”
$image->print();

Malformed srcset values will throw a MalformedSrcSetStringException. These are srcset values that don’t follow the standard HTML format or the shorthand format.

If for some reason you want to, you can pass in an array o’ SrcSetItem instances ’stead o’ a string:

use WaughJ\HTMLImage\HTMLImage;
use WaughJ\HTMLImage\SrcSetItem;

$image = new HTMLImage
(
    "demo.png",
    null,
    [ 'srcset' => [ new SrcSetItem( 'demo', 300, 300, 'png' ), new SrcSetItem( 'demo', 800, 500, 'png' ), new SrcSetItem( 'demo', 1280, -1, 'png' ) ] ]
);

// Will output “<img src="demo.png" srcset="demo-300x300.png 300w, demo-800x500.png 800w, demo.png 1280w" sizes="(max-width: 300px) 300px, (max-width: 800px) 800px, 1280px" alt="" />”
$image->print();

As shown, to make a srcset item keep the base filename & only use the width as a width tag, pass -1 for height.

You can also pass in a SrcSet instance instead o’ an array, which can take in an array o’ SrcSetItem instances, an array o’ strings, or a string. ( All o’ the options shown here are simply passed into a SrcSet constructor, including a SrcSet instance, in the backend, anyway ).

Error Handling

The HTMLImage constructor may throw a WaughJ\FileLoader\MissingFileException exception if it is set to show a version tag ( the default ) & it can't access the file to get its modified date ( usually caused by the file not being where it's expected to be ). This exception includes in its getFallbackContent method with an HTMLImage object with the versionless source for easy recovery like so ( while the getFilename method can be used to find where it's trying to find the file on the server ):

use WaughJ\HTMLImage\HTMLImage;
use WaughJ\FileLoader\FileLoader;
use WaughJ\FileLoader\MissingFileException;

try
{
    $image = new HTMLImage
    (
        'image.png',
        new FileLoader([ 'directory-url' => 'https://www.example.com' ]),
        [
            'class' => 'center-img ornate',
            'width' => '600',
            'height' => '400'
        ]
    );
}
catch ( MissingFileException $e )
{
    // Maybe log somewhere that it couldn't find the file located @ $e->getFilename().
    $image = $e->getFallbackContent(); // This will be the equivalent o' the image with its 'show_version' property false.
}

$image->print(); // Will still work, e'en if an exception is thrown.

As mentioned in the Responsive Images section, malformed srcset values will throw a MalformedSrcSetStringException.

Changelog

0.9.0

0.8.0

0.7.0

0.6.0

0.5.0

0.4.0

0.3.0

0.2.0

0.1.0


All versions of html-image with dependencies

PHP Build Version
Package Version
Requires php Version >=7.0
waughj/html-attribute-list Version >=1.1.0
waughj/test-hash-item Version >=2.0.0
waughj/file-loader Version >=0.5.4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package waughj/html-image contains the following files

Loading the files please wait ....