PHP code example of imactool / hyperf-stable-diffusion
1. Go to this page and download the library: Download imactool/hyperf-stable-diffusion 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/ */
imactool / hyperf-stable-diffusion example snippets
use Imactool\HyperfStableDiffusion\Prompt;
use Imactool\HyperfStableDiffusion\Replicate;
$result = Replicate::make()->withPrompt(
Prompt::make()
->with('a panda sitting on the streets of New York after a long day of walking')
->photograph()
->resolution4k()
->trendingOnArtStation()
->highlyDetailed()
->dramaticLighting()
->octaneRender()
)->inputParams('num_outputs', 1)
->generate(); //根据不同的模型来传递生成的张数
use Imactool\HyperfStableDiffusion\Prompt;
use Imactool\HyperfStableDiffusion\Replicate;
use Intervention\Image\ImageManager;
//这里使用了 intervention/image 扩展来处理图片文件,你也可以更换为其他的
$sourceImg = (string) (new ImageManager(['driver' => 'imagick']))->make('path/image/source.png')->encode('data-url');
$prompt = 'Petite 21-year-old Caucasian female gamer streaming from her bedroom with pastel pink pigtails and gaming gear. Dynamic and engaging image inspired by colorful LED lights and the energy of Twitch culture, in 1920x1080 resolution.';
$result = Replicate::make()
->converVersion('a991dcab77024471af6a89ef758d98d1a54c5a25fc52a06ccfd7754b7ad04b35')
->withPrompt(
Prompt::make()
->with($prompt)
)
->inputParams('image',$sourceImg)
->inputParams('negative_prompt', 'disfigured, kitsch, ugly, oversaturated, greain, low-res, Deformed, blurry, bad anatomy, disfigured, poorly drawn face, mutation, mutated, extra limb, ugly, poorly drawn hands, missing limb, blurry, floating limbs, disconnected limbs, malformed hands, blur, out of focus, long neck, long body, ugly, disgusting, poorly drawn, childish, mutilated, mangled, old, surreal, calligraphy, sign, writing, watermark, text, body out of frame, extra legs, extra arms, extra feet, out of frame, poorly drawn feet, cross-eye, blurry, bad anatomy')
->inputParams('strength', 0.5)
->inputParams('upscale', 2)
->inputParams('num_inference_steps', 25)
->inputParams('guidance_scale', 7.5)
->inputParams('scheduler', 'EulerAncestralDiscrete')
->inputParams('num_outputs', 1)
->generate();
use Imactool\HyperfStableDiffusion\Replicate;
$freshResults = Replicate::get($replicate_id);
use Imactool\HyperfStableDiffusion\StableDiffusion;
$res = StableDiffusion::make()
->useDreamboothApiV4()
->withPayload('key', '')
->withPayload('model_id', 'anything-v4')
->withPayload('prompt', 'ultra realistic close up portrait ((beautiful pale cyberpunk female with heavy black eyeliner)), blue eyes, shaved side haircut, hyper detail, cinematic lighting, magic neon, dark red city, Canon EOS R3, nikon, f/1.4, ISO 200, 1/160s, 8K, RAW, unedited, symmetrical balance, in-frame, 8K')
->withPayload('negative_prompt', 'painting, extra fingers, mutated hands, poorly drawn hands, poorly drawn face, deformed, ugly, blurry, bad anatomy, bad proportions, extra limbs, cloned face, skinny, glitchy, double torso, extra arms, extra hands, mangled fingers, missing lips, ugly face, distorted face, extra legs, anime')
->withPayload('width', '512')
->withPayload('height', '512')
->withPayload('samples', '1')
->withPayload('num_inference_steps', '30')
->withPayload('seed', null)
->withPayload('guidance_scale', '7.5')
->withPayload('webhook', null)
->withPayload('track_id', null)
->text2img();
var_dump( $res);