batdan/midjourney-api-php

生成Midjourney图像(Discord API)。接受提示中的URL

v2.1.4 2023-07-21 07:43 UTC

README

此PHP库为使用Midjourney Bot创建图像提供了用户友好的界面,利用Discord API的功能。

本版本具有将示例图像通过URL 嵌入到Midjourney提示中的功能,与 私有和公共频道 完全兼容。

安装

您可以使用Composer将此库无缝集成到项目中。为此,请在项目的根目录中执行以下命令

composer require batdan/midjourney-api-php

使用方法

基本使用说明

要使用Midjourney Bot生成图像,请初始化Midjourney类的实例

use batdan\ai\MidjourneyImageCreator;

$discordChannelId = 'YOUR_DISCORD_CHANNEL_ID';
$discordUserToken = 'YOUR_DISCORD_USER_TOKEN';

$midjourney = new MidjourneyImageCreator($discordChannelId, $discordUserToken);

// Example of a prompt: text is separated from tags
$promptText = "aerial view of a giant fish tank shaped like a tower in the middle of new york city, https://depuismonhamac.jardiland.com/wp-content/uploads/2019/06/AdobeStock_196378179.jpeg";
$promptTags = "8k octane render, photorealistic --ar 9:20 --v 5";

/**
 * The imageCreationV2 method is responsible for randomly selecting an image from the 4 options provided by Midjourney.
 * If you want to specify a particular image, you can pass its identifier (ranging from 0 to 3) as the third parameter.
 * 
 * Example: $midjourneyImageCreator->imageCreation($promptText, $promptTags, 0);
 *
 * This will generate an image for the given prompt, using the specified image identifier (in this case, 0).
 */
$message = $midjourney->imageCreationV2($promptText, $promptTags);
$imgUrl  = $message->upscaled_photo_url;

echo chr(10) . chr(10);
echo $imgUrl;
echo chr(10) . chr(10);

构造函数

  • $discordChannelId:

    • 将此值替换为Midjourney Bot已安装的频道ID。您可以通过在频道上右键单击并 选择复制频道ID 来获取频道ID。
    • 请记住,您可以将Midjourney Bot邀请到自己的服务器,以便更好地组织工作。有关更多信息,请参阅 https://docs.midjourney.com/docs/invite-the-bot

  • $discordUserToken:

    • 要获取您的Discord用户令牌,您需要使用浏览器中的开发者工具并查看网络数据。以下是步骤

      • 在浏览器中打开Discord(不是应用程序)。
      • 打开开发者工具(您通常可以通过按F12或在Windows/Linux上按Ctrl + Shift + I或在MacOS上按Cmd + Option + I来打开)。
      • 导航到 “网络” 选项卡。
      • 在过滤器框中,键入 “messages” 以缩小网络请求列表。
      • 在任何Discord频道中发送一条消息。



      • 查看发送消息后出现的网络请求,选择名称中包含 “messages” 的请求。
      • 在“头部”选项卡中,查找名为“Authorization”的请求头。此头的值 就是您的用户令牌



    重要提示:请务必严格保密您的用户令牌。任何拥有您令牌的人都可以控制您的Discord账户。永远不要与他人分享它,也不要将其发布在网上。如果您认为您的令牌可能已被泄露,请立即更改密码,因为这会使您当前的有效令牌失效。

最佳性能:考虑使用CLI脚本

为了确保最佳性能并避免任何潜在的执行时间问题,我们建议使用CLI(命令行界面)脚本执行任务。CLI脚本提供了一个简化和高效的执行环境,允许更快的处理和更平滑的执行。

在运行脚本之前,请在 example.php 文件中填写 频道ID用户令牌




此过程可能需要大约一分钟。

自动生成的图像