1. Go to this page and download the library: Download exeque/placehold-dot-co library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
exeque / placehold-dot-co example snippets
use ExeQue\PlaceholdDotCo\Data\Format;
use ExeQue\PlaceholdDotCo\Data\Image;
use ExeQue\PlaceholdDotCo\Placehold;
$placehold = new Placehold();
/** @var Image $image */
$image = $placehold->builder()
->size(1920, 1080)
->color('black', 'white')
->format(Format::JPEG)
->text('Hello World')
->get();
$image->size; // Byte size
$image->contents; // Image contents as string
$image->mime; // Image mime type
$image->uri; // Image URI
$image->detach(); // Detach the data stream from the object
use ExeQue\PlaceholdDotCo\Placehold;
$placehold = new Placehold();
$builder = $placehold->builder();
$builder->size(1920, 1080);
$builder->width(1920);
$builder->height(1080);
$builder->square(1000);
use ExeQue\PlaceholdDotCo\Data\Format;
use ExeQue\PlaceholdDotCo\Placehold;
$placehold = new Placehold();
$builder = $placehold->builder();
$builder->color('black', 'white'); // background black, text white
$builder->color('F00', 'FFF'); // background #F00, text #FFF
$builder->color('FF0000', 'FFFFFF'); // background #FF0000, text #FFFFFF
$builder->color('transparent', 'black'); // background transparent, text black
$builder->background('black'); // background black
$builder->foreground('black'); // text black (background white)
use ExeQue\PlaceholdDotCo\Placehold;
$placehold = new Placehold();
$builder = $placehold->builder();
$builder->text('Hello World'); // Single line "Hello World"
$builder->text("Hello\nWorld"); // Multi line text "Hello\nWorld"
$builder->noText(); // remove text
use ExeQue\PlaceholdDotCo\Data\Font;
use ExeQue\PlaceholdDotCo\Placehold;
$placehold = new Placehold();
$builder = $placehold->builder();
// Lato
$builder->font(Font::Lato);
$builder->lato();
// Lora
$builder->font(Font::Lora);
$builder->lora();
// Montserrat
$builder->font(Font::Montserrat);
$builder->montserrat();
// Noto Sans
$builder->font(Font::NotoSans);
$builder->notoSans();
// Open Sans
$builder->font(Font::OpenSans);
$builder->openSans();
// Oswald
$builder->font(Font::Oswald);
$builder->oswald();
// Playfair Display
$builder->font(Font::PlayfairDisplay);
$builder->playfairDisplay();
// Poppins
$builder->font(Font::Poppins);
$builder->poppins();
// PT Sans
$builder->font(Font::PTSans);
$builder->ptSans();
// Raleway
$builder->font(Font::Raleway);
$builder->raleway();
// Roboto
$builder->font(Font::Roboto);
$builder->roboto();
// Source Sans Pro
$builder->font(Font::SourceSansPro);
$builder->sourceSansPro();
use ExeQue\PlaceholdDotCo\Builder;
use ExeQue\PlaceholdDotCo\Placehold;
$placehold = new Placehold();
$builder = $placehold->builder();
$condition = true;
$callableCondition = fn() => true;
$builder
->when($condition, fn(Builder $builder) => $builder->square(400))
->when($callableCondition, fn(Builder $builder) => $builder->square(400));
use ExeQue\PlaceholdDotCo\Placehold;
$builder = $placehold->builder();
$builder->uri(); // URI of the image as a PSR-7 compatible UriInterface
use ExeQue\PlaceholdDotCo\Placehold;
$placehold = new Placehold();
$builder = $placehold->builder()->size(1920, 1080)->png();
// The batch method returns a generator function that can be used to fetch the images. Any indices can be used as keys.
$generator = $placehold->batch([
'first' => $builder->text('First Image'),
'second' => $builder->text('Second Image'),
]);
foreach ($generator as $index => $image) {
// Do something with the image
}
// The generator function will return the images as they are fetched.
$images = iterator_to_array($generator);
$images['first']; // URI of the first image
$images['second']; // URI of the second image
use ExeQue\PlaceholdDotCo\Cache\ImageStore;
use ExeQue\PlaceholdDotCo\Client;
use ExeQue\PlaceholdDotCo\Placehold;
// Store the images in system temp directory (default)
$store = ImageStore::temp();
// Store the images in a custom directory
$store = ImageStore::file('path/to/cache');
// Store the images in memory
$store = ImageStore::memory();
// Store the images in a null store (no caching)
$store = ImageStore::null();
$placehold = new Placehold(
new Client(
imageStore: $store
)
)
use ExeQue\PlaceholdDotCo\Faker\ImageProvider;
use ExeQue\PlaceholdDotCo\Placehold;
use Faker\Factory;
use Faker\Generator;
$provider = new ImageProvider(
new Placehold() // [Optional] Can be configured with a Placehold instance
);
/** @var Generator|ImageProvider $faker */
$faker = Factory::create();
$faker->addProvider($provider);
$faker->placeholdCoUrl(); // Create a url for a placeholder image
$faker->placeholdCoImage(); // Create a placeholder image as a string
$faker->placeholdCoResource(); // Create a placeholder image as a resource
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.