承接 thehocinesaad/stability-php 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

thehocinesaad/stability-php

最新稳定版本:v0.1.0

Composer 安装命令:

composer require thehocinesaad/stability-php

包简介

Stability PHP is a comprehensive PHP API client designed for seamless interaction with the Stability AI API.

README 文档

README

Stability PHP example code.

Stability PHP is a PHP API client offering developers an intuitive and efficient interface to interact seamlessly with the Stability AI API.

Table of Contents

Installation

You can install the package via composer:

composer require thehocinesaad/stability-php

After that, you can start using it:

$client = Stability::client('YOUR_API_KEY');

$response = $client->generations()->textToImage('stable-diffusion-xl-1024-v1-0', [
    'text_prompts' => [
        [
            'text' => 'A lighthouse on a cliff',
            'weight' => 0.5
        ],
    ],
    'samples' => 1,
]);

dd($response['artifacts'][0]['base64']);
// "iVBORw0KGgoAAAANSUhEUgAABAAAAAQACAIAAADwf7zUAAM8MmNhQ..." - Image encoded in base64.

You can add additional HTTP headers (which the API supports) to requests:

$client = Stability::client(YOUR_API_KEY')
    ->withAcceptHeader('image/png')
    ->withOrganizationHeader('org-123456')
    ->withStabilityClientIdHeader('my-great-plugin')
    ->withStabilityClientVersionHeader('1.2.1');

Usage

User

Manage your Stability.ai account, and view account/organization balances.

Account

Get information about the account associated with the provided API key.

$response = $client->user()->account();

$response['email']; // 'your@email.com'
$response['id']; // 'user-xxxxxxxxxxxxxxx'
// ...

Balance

Get the credit balance of the account/organization associated with the API key.

$response = $client->user()->balance();

$response['credits']; // 1000000 😍

Engines

Enumerate available engines.

List

List all engines available to your organization/user.

$response = $client->engines()->list();
// Returns an array of available engines.

foreach ($response as $engine) {
    $engine['description']; // 'Stability-AI Stable Diffusion XL v1.0'
    $engine['id']; // 'stable-diffusion-xl-1024-v1-0'
    $engine['name']; // 'Stable Diffusion XL v1.0'
    $engine['type']; // 'PICTURE'
}

Generations

Generate images from text, existing images, or both.

Text to Image

Generate a new image from a text prompt.

$response = $client->generations()->textToImage('stable-diffusion-xl-1024-v1-0', [
    'text_prompts' => [
        [
            'text' => 'A lighthouse on a cliff',
        ],
    ],
    'cfg_scale' => 7,
    'height' => 1024,
    'width' => 1024,
    'steps' => 30,
    'samples' => 2,
]);

foreach ($response['artifacts'] as $result) {
    $result['base64']; // 'iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAIAAA...'
    $result['seed']; // 6311659811
    $result['finishReason']; // 'SUCCESS'
}

Image to Image

Modify an image based on a text prompt.

$response = $client->generations()->imageToImage(stable-diffusion-xl-1024-v1-0', [
    'init_image' => 'init_image.png',
    'init_image_mode' => 'IMAGE_STRENGTH',
    'image_strength' => '0.35',
    'text_prompts' => [
        [
            'text' => 'A lighthouse on a cliff',
        ],
    ],
    'cfg_scale' => 7,
    'steps' => 10,
    'samples' => 2,
]);

foreach ($response['artifacts'] as $result) {
    $result['base64']; // 'iVBORw0KGgoAAAANSUhEUgAABAAAAAQACAIAAA...'
    $result['seed']; // 4285698893
    $result['finishReason']; // 'SUCCESS'
}

Image to Image Upscale

Create a higher resolution version of an input image.

$response = $client->generations()->imageToImageUpscale('esrgan-v1-x2plus', [
    'image' => 'image.png',
    'width' => '1024',
]);

$response['artifacts'][0]['base64']; // 'iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAIAAAB7GkOtAAD...'
$response['artifacts'][0]['seed']; // 0
$response['artifacts'][0]['finishReason']; // 'SUCCESS'

Image to Image Masking

Selectively modify portions of an image using a mask.

$response = $client->generations()->imageToImageMasking('stable-inpainting-512-v2-0', [
    'mask_source' => 'MASK_IMAGE_BLACK',
    'init_image' => 'init_image.png',
    'mask_image' => 'mask_image.png',
    'text_prompts' => [
        [
            'text' => 'A lighthouse on a cliff',
        ],
    ],
    'cfg_scale' => 7,
    'clip_guidance_preset' => 'FAST_BLUE',
    'steps' => 10,
    'samples' => 2,
]);

foreach ($response['artifacts'] as $result) {
    $result['base64']; // 'iVBORw0KGgoAAAANSUhEUgAABAAAAAQACAIAAADwf7...'
    $result['seed']; // 96898585
    $result['finishReason']; // 'SUCCESS'
}

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 4.98k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 3
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-11-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固