PHP code example of ediasoft / midjourney-api-php

1. Go to this page and download the library: Download ediasoft/midjourney-api-php 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/ */

    

ediasoft / midjourney-api-php example snippets


use eDiasoft\Midjourney\MidjourneyApiClient;

$channel_id = 00000000;
$authorization = "AUTH_TOKEN";

$midjourney = new MidjourneyApiClient($channel_id, $authorization);

$result = $midjourney->imagine('Elephant and a snake romantically having a diner')->send();

return $result;

$imagine_builder = $midjourney->imagine('Elephant and a snake romantically having a diner'); //Returns a Builder object

$imagine_builder->aspectRatio('16:9') //Changing the aspect ratio.
                ->chaos(30) //The higher the chaos the more unusual and unexpected results.
                ->fast() //Enable fast mode for this single job.
                ->imageWeight(1.75) //Sets image prompt weight relative to text weight. The default value is 1.
                ->no('moon roses') //Exclude specific object in the image.
                ->quality(0.5)
                ->relax() //This will turn on relax mode for this single job, the interval of retrieving the image will be also delayed. 
                ->repeat(40) //Create multiple Jobs from a single prompt.
                ->seed(1000) //The Midjourney bot uses a seed number to create a field of visual noise, like television static, as a starting point to generate the initial image grids.
                ->stop(35) //Stopping a Job at an earlier percentage can create blurrier, less detailed results.
                ->style('cute')
                ->stylize(5) //Influences how strongly Midjourney's default aesthetic style is applied
                ->tile() //Generates images that can be used as repeating tiles to create seamless patterns.
                ->turbo() //Override your current setting and run a single job using Turbo Mode.
                ->weird(1000); //Explore unusual aesthetics with the experimental weird parameter

$result = $imagine_builder->send()

$message_id = "1234"
$upscale_image_id = "MJ::JOB::upsample::1::xxxxx";
$interaction_id = $result->interactionId() //You can retrieve this ID after the imagine interaction is performed, this is a identifier for the specific job request.

$upscale_builder = $midjourney->upscale($message_id, $upscale_image_id, $interaction_id); //Returns a Builder object

$upscaled_image_result = $upscale_builder->send();