Image variation and edition

This Markdown file can be "evaluated" with the Raku package "Text::CodeProcessing", [AAp2]. Here is a shell command:


file-code-chunks-eval Image-variation-and-edition.md

Remark: For doing image generations using text prompts see the document Image-generation.md (and its woven version, Image-generation_woven.md .)


Image variation

Here we load the Raku package "WWW::OpenAI", [AAp1]:


use WWW::OpenAI;

# (Any)

Variations of images can be generated with the function openai-variate-image -- see the section "Images" of [OAI2].

Here is a (random mandala) image:

Remark: Below we refer to the image above as "the original image."

Here we generate a few variations of the image above, and get "whole images" in Base64 format :


my @imgResB64 = |openai-variate-image(
        $*CWD ~ '/../resources/RandomMandala.png',
        n => 2,
        size => 'small',
        response-format => 'b64_json',
        format => 'values',
        method => 'tiny');

@imgResB64.map({ '![](data:image/png;base64,' ~ $_ ~ ')' }).join("\n\n")

Remark: The obtained images are put into the woven document via the output of the code cell, which has the setting results=asis .

The first argument is a prompt used to generate the image(s).

Here are the descriptions of the named arguments (options):

Here we generate a few variations of the original mandala image above, get their URLs, and place (embed) the image links using a table:


my @imgRes = |openai-variate-image(
        $*CWD ~ '/../resources/RandomMandala.png',
        response-format => 'url',
        n => 2,
        size => 'small',
        format => 'values',
        method => 'tiny');

@imgRes.map({ '![](' ~ $_ ~ ')' }).join("\n\n")


Image edition

Editions of images can be generated with the function openai-edit-image -- see the section "Images" of [OAI2].

Here are the descriptions of positional arguments:

Here are the descriptions of the named arguments (options):

Here is a random mandala color (RGBA) image:

Here we generate a few editions of the colored mandala image above, get their URLs, and place (embed) the image links using a table:


my @imgRes = |openai-edit-image(
        $*CWD ~ '/../resources/RandomMandala2.png',
        'add cosmic background',
        response-format => 'url',
        n => 2,
        size => 'small',
        format => 'values',
        method => 'tiny');

@imgRes.map({ '![](' ~ $_ ~ ')' }).join("\n\n")


References

Articles

[AA1] Anton Antonov, "Connecting Mathematica and Raku" , (2021), RakuForPrediction at WordPress .

Packages

[AAp1] Anton Antonov, WWW::OpenAI Raku package , (2023), GitHub/antononcube .

[AAp2] Anton Antonov, Text::CodeProcessing , (2021), GitHub/antononcube .

[OAI1] OpenAI Platform, OpenAI platform .

[OAI2] OpenAI Platform, OpenAI documentation .

[OAIp1] OpenAI, OpenAI Python Library , (2020), GitHub/openai .