ferranfg/midjourney-php

This package is abandoned and no longer maintained. No replacement package was suggested.

Generate images using Midjourney Bot through the Discord API.

Fund package maintenance!
Ko Fi

v2.2.0 2023-12-08 10:16 UTC

This package is auto-updated.

Last update: 2024-05-08 11:41:26 UTC


README

This PHP library provides a simple interface for generating images using the Midjourney Bot through the Discord API.

Midjourney PHP Library for Discord API

Installation

You can install this library using Composer. Run the following command in your project directory:

composer require ferranfg/midjourney-php

Usage

Basic usage

To generate an image using the Midjourney Bot, you first need to create an instance of the Midjourney class:

use Ferranfg\MidjourneyPhp\Midjourney;

$midjourney = new Midjourney($discord_channel_id, $discord_user_token);

$message = $midjourney->generate('An astronaut riding a horse');

return $message->upscaled_photo_url;

Constructor

  • $discord_channel_id - Replaces this value with the Channel ID where the Midjourney Bot is installed. You can get the Channel ID right-clicking on the channel and Copy Channel ID.

    Remember that you can invite the Midjourney Bot to your own server to organize your work https://docs.midjourney.com/docs/invite-the-bot

  • $discord_user_token - Automatic user accounts (self-bots) are not allowed by Discord and can result in an account termination if found, so use it at your own risk.

    To get your user token, visit https://discord.com/channels/@me and open the Network tab inside the Developers Tools. Find between your XHR requests the Authorization header.

    Discord User Token

Methods

$midjourney->imagine($prompt)

This method generates an image using a prompt and returns an object that represents the message containing the generated image. The $prompt parameter is a string that will be used to generate the image.

$imagine_object = $midjourney->imagine('An astronaut riding a horse');

$midjourney->getImagine($prompt)

This method returns a previously generated object that represents the message containing the image generated by the given prompt. The $prompt parameter is the string used to generate the image.

$imagine_object = $midjourney->getImagine('An astronaut riding a horse');

$midjourney->upscale($imagine_object, $upscale_index)

This method upscales an image contained in the given object and returns the URL of the upscaled image. The $imagine_object parameter is the object returned from the imagine / getImagine methods. The $upscale_index parameter is an integer between 0 and 3 that represents the option provided by the MJ bot we want to upscale.

$upscaled_image_url = $midjourney->upscale($imagine_object, 2);

$midjourney->getUpscale($imagine_object, $upscale_index)

This method returns the URL of a previously upscaled image generated by the given message and with the given option of upscaling. The $imagine_object parameter is the object returned from the imagine / getImagine methods. The $upscale_index parameter is an integer between 0 and 3 that represents the option provided to the MJ bot we upscaled.

$upscaled_image_url = $midjourney->getUpscale($imagine_object, 2);