Download the PHP package exeque/placehold-dot-co without Composer
On this page you can find all versions of the php package exeque/placehold-dot-co. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download exeque/placehold-dot-co
More information about exeque/placehold-dot-co
Files in exeque/placehold-dot-co
Package placehold-dot-co
Short Description Wrapper for Placehold.co placeholder images
License MIT
Informations about the package placehold-dot-co
Placehold.co
Wrapper for placehold.co to generate placeholder images.
It supports the full API of placehold.co and provides a fluent interface to build the images.
Installation
You can install this package via composer:
Usage
The Image Object
The image object contains the following properties:
size
: The size of the image in bytes.contents
: The contents of the image as a string.mime
: The mime type of the image.uri
: The URI of the image.
The image is stored using a php://temp
resource to reduce memory usage.
The resource is automatically closed when the object is destroyed.
Basic Usage
Images can be generated using the builder()
method.
The Builder
class provides an immutable fluent interface to build the image.
Size
By default, the images are created as 300x300, but you can change the size.
It is also possible to change the orientation of the image by using the landscape()
and portrait()
methods.
Retina
You can also create retina images by using the retina()
method.
Only supported for:
- JPEG
- PNG
- GIF
- WEBP
- AVIF
Format
You can change the image format by using the format()
or format specific methods.
Color
You can change the background and text color by using the color()
, background()
or foreground()
methods.
Note: If you're using the foreground()
method without a background color set it will set the background color to white.
The methods support CSS colors, hex colors (without #), and transparency (via the transparent
color).
Text
You can change the text by using the text()
method.
Existing text will be overwritten - Existing text can be removed by using the noText()
method.
Multiline text is supported and lines are separated by \n
.
Font
You can change the font by using the font()
or specific font methods.
Conditional Methods
If you want to use the builder methods conditionally, you can use the when()
method.
URL Generation
You can also generate the URL for the image by using the url()
method.
Advanced Usage
Batching
The library supports fetching multiple images at once using the batch()
method by leveraging the Guzzle
library's async requests.
You are not guaranteed to get the images in the same order as you requested them, so you should use the keys to identify the images if order matters.
Caching
The library supports caching the images to optimize performance.
By default, the library uses the php://temp
stream to store the images. The cache is handled on the internal HTTP client.
You can also create custom stores by implementing the ExeQue\PlaceholdDotCo\Cache\Contracts\ImageStore
interface.
FakerPHP Provider
This library also provides a FakerPHP provider to generate placeholder images.
Most, but not all, features are available in the Faker
provider.
Check the phpdoc for the ImageProvider
class for more information.
Testing
You can run the tests using the following command:
License
This library is open-sourced software licensed under the MIT license.
All versions of placehold-dot-co with dependencies
guzzlehttp/guzzle Version ^7.0
psr/simple-cache Version ^3.0
webmozart/assert Version ^1.11