1. Go to this page and download the library: Download minhyung/sdwebui 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/ */
minhyung / sdwebui example snippets
use Minhyung\SdWebUi\SdWebUi;
$sd = SdWebUi::create('http://127.0.0.1:7860');
$sd->txt2img()
->prompt('a lighthouse in a storm, dramatic lighting')
->negativePrompt('blurry, lowres')
->size(768, 512)
->steps(30)
->send()
->first()
->saveTo('lighthouse.png');
use GuzzleHttp\Client;
$sd = SdWebUi::create('http://127.0.0.1:7860')
->httpClient(new Client(['timeout' => 600]));
use Symfony\Component\HttpClient\Psr18Client;
use Symfony\Component\HttpClient\HttpClient;
$sd = SdWebUi::create('http://127.0.0.1:7860')
->httpClient(new Psr18Client(HttpClient::create([
'timeout' => 600, // inactivity timeout
'max_duration' => 900, // total ceiling
])));
Image::fromFile('in.png');
Image::fromBinary($bytes);
Image::fromBase64($base64OrDataUri);
Image::fromUrl('https://example.com/in.png'); // the server fetches it
$image->saveTo('out.png');
$image->toBinary();
$image->toBase64(); // bare base64 — what the API wants
$image->format(); // sniffed from magic bytes
$image->dimensions();
$request = $sd->txt2img()->prompt('a cat')->steps(50);
$taskId = $request->taskId(); // hand this to another process
$request->send();
$progress = $sd->progress()->task($taskId);
$progress->percent(); // 42
$progress->eta(); // seconds
$progress->livePreview(); // ?Image
$progress->isFinished();
$progress->isUnknown(); // the server has no record of this id
final class GuardedClient implements \Psr\Http\Client\ClientInterface
{
public function __construct(private \Psr\Http\Client\ClientInterface $inner) {}
public function sendRequest(\Psr\Http\Message\RequestInterface $request): \Psr\Http\Message\ResponseInterface
{
// assert on $request->getUri()->getHost(), start a span, count a metric...
return $this->inner->sendRequest($request);
}
}
$sd = SdWebUi::create('http://127.0.0.1:7860')->httpClient(new GuardedClient($psr18Client));