PHPackages                             waughj/html-picture - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. waughj/html-picture

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

waughj/html-picture
===================

Simple class for easy generation o' picture tag HTML code.

v0.7.2(6y ago)01543AGPL-3.0-or-laterPHPPHP &gt;=7.0

Since May 15Pushed 6y agoCompare

[ Source](https://github.com/waughjai/html-picture)[ Packagist](https://packagist.org/packages/waughj/html-picture)[ RSS](/packages/waughj-html-picture/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (5)Versions (12)Used By (3)

HTML Picture
============

[](#html-picture)

Class for easy generation o' picture tag HTML code.

Use
---

[](#use)

Arguments for constructor:

1. Fallback image as HTMLImage object.
2. Sources as array o' HTMLPictureSource objects.
3. Array o' picture element attributes.

A simpler way to generate these is to use the "generate" static method, which takes the following arguments:

1. String representing base local filename ( don't include extension ).
2. String representing extension ( don't include "."" ).
3. Hash map with optional arguments:
    1. "loader": file loader to help set URL directory in which 1st argument will be treated local to &amp; the server directory for getting the modified date o' the file to break cache corruption. See  for mo' info on how to use this. Can be hash map or FileLoader object.
    2. "img-attributes": HTML attributes that will go in the img tag ( these will affect the image that is shown ).
    3. "picture-attributes": HTML attributes that will go in containing picture tag.
    4. "source-attributes": HTML attributes that will go in every source tag. You probably won't need this. Don't use ID, as it will create multiple IDs, which is invalid.

Example
-------

[](#example)

```
use WaughJ\HTMLPicture\HTMLPicture;

echo HTMLPicture::generate
(
	'photo',
	'jpg',
	'480w 320h, 800w 600h, 1200w 800h',
	[
		'loader' =>
		[
			'directory-url' => 'https://mywebsite.com',
			'directory-server' => getcwd(),
			'shared-directory' => 'tests'
		],
		'img-attributes' => [ 'class' => 'center-img' ],
		'picture-attributes' => [ 'id' => 'slider-42' ],
		'source-attributes' => [ 'class' => 'source-item' ]
	]
);

```

Will print ( #s after "?m=" will vary ):

```

```

### Error Handling

[](#error-handling)

PictureHTML's default o' adding a version to each URL may throw a WaughJ\\FileLoader\\MissingFileException exception when using the static generate method ( but not the regular constructor, which doesn't set any URLs ). This exception contains a fallback version o' the PictureHTML that is equivalent to a version with "show\_version" turned off.

Example:

```
$picture = null;
try
{
	$picture = HTMLPicture::generate
	(
		'iainthere',
		'jpg',
		[
			[ 'w' => 480, 'h' => '320' ],
			[ 'w' => 800, 'h' => 600 ],
			[ 'w' => '1200', 'h' => 800 ]
		],
		[
			'loader' => [ 'directory-url' => 'https://mywebsite.com', 'directory-server' => getcwd(), 'shared-directory' => 'tests' ]
		]
	);
}
catch ( MissingFileException $e )
{
	$picture = $e->getFallbackContent();
}

```

Changelog
---------

[](#changelog)

### 0.7.0

[](#070)

- Add Cached HTML to Make Use o' Same Object Multiple Times Faster

### 0.6.0

[](#060)

- Revamp Error Handling for Missing Files

### 0.5.0

[](#050)

- Add Ability to Easily Cancel Showing Versioning

### 0.4.0

[](#040)

- Add getSources &amp; getPictureAttributes Methods

### 0.3.0

[](#030)

- Change Constructor to Take in HTMLImage &amp; Array o' HTMLPictureSource

### 0.2.0

[](#020)

- Add getFallbackImage &amp; changeFallbackImage Methods

### 0.1.0

[](#010)

- Initial Version

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

11

Last Release

2535d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/11161078?v=4)[waughj](/maintainers/waughj)[@waughj](https://github.com/waughj)

---

Tags

generatorhtmlpicture tag

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/waughj-html-picture/health.svg)

```
[![Health](https://phpackages.com/badges/waughj-html-picture/health.svg)](https://phpackages.com/packages/waughj-html-picture)
```

###  Alternatives

[symfony/maker-bundle

Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.

3.4k111.1M568](/packages/symfony-maker-bundle)[simplesoftwareio/simple-qrcode

Simple QrCode is a QR code generator made for Laravel.

2.9k27.6M92](/packages/simplesoftwareio-simple-qrcode)[caxy/php-htmldiff

A library for comparing two HTML files/snippets and highlighting the differences using simple HTML.

21520.9M15](/packages/caxy-php-htmldiff)[okipa/laravel-table

Generate tables from Eloquent models.

56752.8k](/packages/okipa-laravel-table)[airmanbzh/php-html-generator

PHP html generator

7973.8k5](/packages/airmanbzh-php-html-generator)[shish/microhtml

A minimal HTML generating library

1142.1k2](/packages/shish-microhtml)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
