batdan/midjourney-api-php 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

batdan/midjourney-api-php

最新稳定版本:v2.1.4

Composer 安装命令:

composer require batdan/midjourney-api-php

包简介

Generate images Midjourney (Discord API). URLs in prompt accepted

README 文档

README

This PHP library offers a user-friendly interface for creating images with the Midjourney Bot, leveraging the capabilities of the Discord API.

This version has the capability to incorporate example images via URLs into the Midjourney prompts, providing full compatibility with both private and public channels.

Installation

You can seamlessly integrate this library into your project using Composer. To do so, execute the following command in your project's root directory:

composer require batdan/midjourney-api-php

Usage

Fundamental Usage Instructions

To generate an image with the Midjourney Bot, initiate an instance of the Midjourney class:

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);

Constructor

  • $discordChannelId:

    • Substitute this value with the Channel ID where the Midjourney Bot has been installed. The Channel ID can be obtained by right-clicking on the channel and selecting Copy Channel ID.
    • Keep in mind that you can invite the Midjourney Bot to your own server to better organize your work. For more information, refer to https://docs.midjourney.com/docs/invite-the-bot

  • $discordUserToken:

    • To retrieve your Discord User Token, you will need to use the Developer Tools in your browser and look into the network data. Here are the steps:

      • Open Discord in your browser (not the app).
      • Open the Developer Tools (you can typically open this by pressing F12 or Ctrl + Shift + I on Windows/Linux or Cmd + Option + I on MacOS).
      • Navigate to the "Network" tab.
      • In the filter box, type "messages" to narrow down the list of network requests.
      • Send a message in any Discord channel.



      • Look at the network requests that pop up after sending the message, select the one that has "messages" in its name.
      • Within the Headers tab, look for the request header named "Authorization". The value of this header is your User Token.



    Important Note: Keep your User Token strictly confidential. Anyone who has your token can take control of your Discord account. Never share it with anyone and don't publish it online. If you think your token may have been compromised, change your password immediately as this will cause your current token to become invalid.

Optimal Performance: Consider Using the CLI Script

To ensure optimal performance and avoid any potential execution time issues, we recommend utilizing the CLI (Command Line Interface) script for your task. The CLI script provides a streamlined and efficient environment, allowing for faster processing and smoother execution.

Before running the script, please fill in the Channel ID and User Token in the example.php file:




The process can take approximately one minute.

Automatically Generated Image:



统计信息

  • 总下载量: 2.21k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 22
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 22
  • Watchers: 2
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-06-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固