PHPackages                             accudio/php-plaiceholder - 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. [Image &amp; Media](/categories/media)
4. /
5. accudio/php-plaiceholder

ActiveLibrary[Image &amp; Media](/categories/media)

accudio/php-plaiceholder
========================

PHP implementation of Plaiceholder - CSS, SVG, Base64 and Blurhash image placeholders.

1.1.0(4y ago)72.0k[1 issues](https://github.com/Accudio/php-plaiceholder/issues)Apache-2.0PHPPHP &gt;=7.2

Since Jun 14Pushed 4y ago1 watchersCompare

[ Source](https://github.com/Accudio/php-plaiceholder)[ Packagist](https://packagist.org/packages/accudio/php-plaiceholder)[ Docs](https://github.com/accudio/php-plaiceholder)[ RSS](/packages/accudio-php-plaiceholder/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (1)Versions (3)Used By (0)

 An externally-maintained implementation of  **[ Plaiceholder ](https://github.com/joe-bell/plaiceholder)**

Plaiceholder for PHP
====================

[](#plaiceholder-for-php)

PHP implementation of [Plaiceholder](https://plaiceholder.co/) - CSS, SVG, Base64 and Blurhash image placeholders.

---

Table of Contents
-----------------

[](#table-of-contents)

1. [Introdution](#introduction)
2. [Installation](#installation)
3. [Setup](#setup)
4. [FAQs](#faqs)
5. [License](#license)
6. [Acknowledgements](#acknowledgements)

---

Introduction
------------

[](#introduction)

[Plaiceholder](https://plaiceholder.co/) is a Node.js utility for generating low quality image placeholders. This package is a *re-write in PHP* and distributed via composer.

Plaiceholder for PHP broadly matches the original JS implementation but implements it in pure PHP and hence has a different syntax. **This readme will only cover differences from the JS implementation.**

For information about the strategies available, their pros and cons, and information about the original project check out the [Plaiceholder docs](https://plaiceholder.co/docs).

Installation
------------

[](#installation)

Plaiceholder for PHP should ideally be installed with composer:

```
composer require accudio/php-plaiceholder

```

If using composer, make sure your application includes `require_once 'vendor/autoload.php';`.

You can alternatively download the repo and `require` the appropriate files from `src/` before creating an instance.

Setup
-----

[](#setup)

Whichever strategy you use, you will first need to create an instance of PHPPlaiceholder for your image:

```
$image_path = '/path/to/your/image.jpg';
$placeholder = new accudio\PHPPlaiceholder\PHPPlaiceholder($image_path);
```

The PHPPlaiceholder object accepts an absolute path to the file as stored on your server, or the full URL for a remote image. For local images you may find the PHP function `realpath()` useful for getting the absolute path.

### CSS

[](#css)

CSS strategy has three output modes:

- `style` (default) — Returns CSS properties ready to be inserted into a style attribute;
- `properties` — Returns custom properties with values, useful for greater control over where they are applied;
- `array` — Returns associative array indexed by property name, for the most control.

[CSS strategy on plaiceholder docs](https://plaiceholder.co/docs/usage#css).

```
$css_style = $placeholder->get_css();
// background-image: linear-gradient(...); background-position: 0 0,0 50%,0 100%;
// background-size:100% 33.33%; background-repeat:no-repeat;

$css_properties = $placeholder->get_css('properties');
// --plaice-image: linear-gradient(...); --plaice-position: 0 0,0 50%,0 100%;
// --plaice-size:100% 33.33%; --plaice-repeat:no-repeat;

$css_array = $placeholder->get_css('array');
// [
//   'background-image'    => 'linear-gradient(...)',
//   'background-position' => '0 0,0 50%,0 100%',
//   'background-size'     => '100% 33.33%',
//   'background-repeat'   => 'no-repeat'
// ]
```

### SVG

[](#svg)

SVG returns a string of SVG markup. By default it will include a style attribute with absolute positioning and centering. Pass `false` as a first argument to prevent output of inline styles to do so yourself.

[SVG strategy on plaiceholder docs](https://plaiceholder.co/docs/usage#svg).

```
$svg_with_styles = $placeholder->get_svg();
//
//
//   ...
//

$svg_no_styles = $placeholder->get_svg(false);
//
//
//   ...
//
```

### Base64

[](#base64)

Generates low-resolution image and encodes as base64, including data-uri and format. Ready for inserting into `src` attribute or `url()` css function.

[Base64 strategy on plaiceholder docs](https://plaiceholder.co/docs/usage#base64).

**Note:** Due to a difference in the image library used between plaiceholder and Plaiceholder for PHP (sharp vs ImageMagick), the base64 strategy doesn't look the same. Whereas plaiceholder tweaks the saturation to make the generated image look slightly better, Imagick seems to do fairly well with no tweaking so I've not made changes. Any feedback is appreciated.

```
$base64 = $placeholder->get_base64();
// data:image/jpeg;base64,...
```

### Blurhash

[](#blurhash)

Creates and returns Blurhash string using [php-blurhash by kornrunner](https://github.com/kornrunner/php-blurhash).

[Blurhash strategy on plaiceholder docs](https://plaiceholder.co/docs/usage#blurhash).

**Note:** Due to a difference in blurhash encoder between plaiceholder and Plaiceholder for PHP, the blurhash strategy can look slightly different in some cases. I am not familiar with blurhash but if someone who is more knowledgeable here can contribute please do.

```
$blurhash = $placeholder->get_blurhash();
// UqF}a5-WR*xw~E$+WBt8-DxHWBa$$-xHWBai
```

FAQs
----

[](#faqs)

- [When should I generate plaiceholders?](#shen-should-i-generate-plaiceholders)
- [Is there a plugin for xyz?](#is-there-a-plugin-for-xyz)

### When should I generate plaiceholders?

[](#when-should-i-generate-plaiceholders)

Although you are able to perform plaiceholder generation on each request, it is not recommended. Especially for large images generation can take a bit of time and resources. This is made even worse by remote images, which require an additional connection in order to download the image to the server.

In production ideally you should store results in a database or file cache so you only need to generate plaiceholders for new or changed images.

### Is there a plugin for XYZ?

[](#is-there-a-plugin-for-xyz)

There are currently no plugins for PHP CMS' or otherwise. I would be keen for plugins for Craft CMS and perhaps WordPress, but not at this time.

Plaiceholder for PHP is fairly simple so likely able to integrate with most platforms easily. I encourage you to make your own integrations, or feel free to build and release plugins or libraries on top of Plaiceholder for PHP - following the [plaiceholder contribution guide](https://github.com/joe-bell/plaiceholder/blob/main/CONTRIBUTING.md).

---

License
-------

[](#license)

Apache-2.0 License © [Alistair Shepherd](https://alistairshepherd.uk)

Acknowledgements
----------------

[](#acknowledgements)

#### [Joe Bell](https://github.com/joe-bell) ([Plaiceholder](https://github.com/joe-bell/plaiceholder))

[](#joe-bell-plaiceholder)

Copyright © 2020-2021, Joe Bell. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License").

#### [Boris Momčilović](https://github.com/kornrunner) ([php-blurhash](https://github.com/kornrunner/php-blurhash))

[](#boris-momčilović-php-blurhash)

MIT License copyright © Boris Momčilović. All Rights Reserved.

#### [Imagick](https://github.com/Imagick/imagick)

[](#imagick)

Copyright (c) 1999 - 2011 The PHP Group. All rights reserved.

###  Health Score

26

—

LowBetter than 46% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~1 days

Total

2

Last Release

1740d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/fe3aa8cc74269d35d35bf30678e6a0db5ad72e4204041bafea8db1a306310705?d=identicon)[Accudio](/maintainers/Accudio)

---

Top Contributors

[![Accudio](https://avatars.githubusercontent.com/u/6884757?v=4)](https://github.com/Accudio "Accudio (9 commits)")

### Embed Badge

![Health badge](/badges/accudio-php-plaiceholder/health.svg)

```
[![Health](https://phpackages.com/badges/accudio-php-plaiceholder/health.svg)](https://phpackages.com/packages/accudio-php-plaiceholder)
```

###  Alternatives

[spatie/image-optimizer

Easily optimize images using PHP

2.9k68.9M89](/packages/spatie-image-optimizer)[liip/imagine-bundle

This bundle provides an image manipulation abstraction toolkit for Symfony-based projects.

1.7k37.7M203](/packages/liip-imagine-bundle)[meyfa/php-svg

Read, edit, write, and render SVG files with PHP

54413.4M35](/packages/meyfa-php-svg)[bkwld/croppa

Image thumbnail creation through specially formatted URLs for Laravel

508489.5k18](/packages/bkwld-croppa)[intervention/image-laravel

Laravel Integration of Intervention Image

1445.8M73](/packages/intervention-image-laravel)[intervention/gif

Native PHP GIF Encoder/Decoder

5518.1M9](/packages/intervention-gif)

PHPackages © 2026

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