Custom module (node) - AI Image manipulation via GTP-image-1/1.5

AI Image Manager

Developed to support an idea by @TMR , this module allows the manipulation of an uploaded image by means of a text prompt to transform the original image

Wappler AI Image Manager leverages the amazing GPT-image-1 or 1.5 endpoints (currently by far the most effective endpoints) to perform the transformation.

As the processes can be quite lengthy, support for messaging while running is enabled via sockets to send progress messages to the client page.

The perfect solution for everything from App content production to online custom merchandising, I hope you will find this extension useful.

Installing

Install is via the project manager:

or via npm install of
@hyperbytes/wappler-image-manager

https://www.npmjs.com/package/@hyperbytes/wappler-image-manager

Using the module

The module should be found in the AI Tools group as "AI Image Editor"
Add the module to your API action

Image Input.

This is the local path to a file currently saved on your server (use file upload if necessary). This is the image that the changes will be applied to.

Prompt

These are the instruction to AI as to what must be done with the image.

OpenAi API Key

If omitted, the module will look in the Environment variables for a entry "OPENAI_API_KEY". This is the most secure way of doing things however you can override this when testing by adding a key manually.

Socket Name

Optionally, sockets can be used to pass linited status updates to the client page while processing. If this is needed then add the socket name here. For example, an entry "ai_update" would look for this socket.


More on this later

Unique Socket ID

To ensure that the emit message is not broadcast to all users, the message should be targeted to the current user. This is done by binding the the socket ID provided from the calling page (more on this later).
Socket ID is only mandatory if the Sockets Action Name is specified.

Save Path.

This is the directory into which you want the result saved. The file name will be preserved.

Chat GPT Engine.

Select v 1.0 or 1.5

Emit Messages

The stages at which messages are sent is coded into the module however the actual message can be amended. If socket use is selected, 6 messages are expected although they can be blank in which case the message is not sent.

Background Transparency.

This will try to enforce background transparency on the final image

Usage Examples

Here we upload an image from app connect using a standard file upload as $_POST.myfile.
If using sockets we need to add the app connect socket component.

image
and send the socket.id as a file upload option using a hidden form input

Binding the value to the value of the socket.id (found in picker)

In our API action, we define the POST inputs.


I give simple instructions to give me long hair, a pretty random instruction so let's see what happens.

I send a passport style image:

I see a response and the number of tokens used:

{"AII":{"url":"/assets/ai_savefolder/passport.jpg","total_tokens":8503}}

and the image is transformed to:

Lets try another with sockets enables.

I define a socket called "ai_update" with the following inputs and emit action.

"message" and "socket_id" are coded into the module as emit() outputs.

We add the name to the module and bind the socket is parameter send from the form.

Now as the module runs, the messages will be emitted from the module, via the socket back to the client with that specific socket id.

In this image of the app connect page, i have changed the socket id input to text from hidden for display purposes where you can clearly see the socket id displayed.

The returned socket messages can be captured via the dynamic message event of the app connect component and displayed however you with. A simple notification works well.

In this case i will use an old black and white image of me at 16 years old.

and ask for it to be colourised

Lastly, a more sophisticated prompt from @TMR which initiated this idea

His prompt was similar but not exactly this:
You are designing official visual assets for WEIM CRIME, a premium parody brand that blends real police-department aesthetics with deadpan humour. The style must always feel official, structured, and cinematic, like a serious law-enforcement document- never cartoonish or childish.

Visual tone: • Clean • High-contrast • Professional • Slightly ironic The output must look like a real investigative asset created by a police department that happens to deal exclusively with Weimaraners. we need to create a WEIM CRIME MUGSHOT TEMPLATE using the supplied image make sure the image is an accurate lifelike depiction of the supplied photo do not change the eyes or the face - show only the dogs head and shoulders, no paws- medium quality1 Canvas Sizenon-transparent canvas- 1080×1350 Meta‑optimised portrait- Weim Grey #7A7F862 Background LayerMugshot Height Chart- Horizontal black lines every 80px- Line thickness: 4px- Numbers on left side: 20, 30, 40, 50, 60 Oswald Bold, Mugshot Black #1A1A1A- Slight vignette around edges 3. Photo Area Centered square frame- 900×900- Thin Gunmetal border #4A4F55- Drop shadow: subtle, 20% opacity- This is where the Weimaraner photo goes4. Header BarTop Banner:- Background: Evidence Tag Orange #FF7A21- Height: 120px- Text: WEIMCRIME MUGSHOT- Font: Oswald Bold, white, 90pt- Alignment: centered- on right hand side police badge with a pawprint in the centre5. Suspect Plate Under PhotoBlack rectangle- Height: 180px- Width: 100%- Background: Mugshot Black #1A1A1A- Text in white Oswald Medium, 60ptFields:- SUSPECT: [Claude]- CRIME: [Bin Diving]- CASE #: WC‑[0124]Spacing:- Each field on its own line- Left‑aligned- 80px padding on left and right6. Stamp Overlay - GUILTY red distressed stamp transparent stamp backgroundPlacement:- Top‑right corner of the photo- 20° rotation for style7. Footer BarBottom Banner:- Background: Gunmetal #4A4F55- Height: 100px- Text:- “WEIM CRIME — GUILTY AS CHARGED”- Font: Inter Medium, white, 48pt- Centered- small centered text at bottom displaying website address: WWW.WEIMCRI.ME

and an image:

Gave:

Pretty amazing yes?

And lastly i fed it with a Wappler logo and asked it to be cartooned.


went to:

This has been tested quite extensively but any issues, let me know

A QUICK BUT IMPORTANT NOTE
Wappler seems to have an issue where if you add an input then later remove it and save, the input is not actually removed from the json file. So, for example, if you remove the socket name and leave it blank to disable socket functions, this may not work. A workaround is to set the content to NULL via the picker.

3 Likes

Trans'formed darling!

:joy:

1 Like

Yes, bit scary isn't it :rofl::rofl:

1 Like

I’ve been extensively testing this and can say its a very powerful extension - most powerful Wappler addition I’ve used so far. Excellent work Brian, very very slick.

I’m not sure which I prefer best, Brians rather fetching blonde hair OR that amazing ‘tache at SIXTEEN years old!!! Id have KILLED for a ‘tache like that at sixteen :slight_smile:

2 Likes

Everyone came to me to buy their booze at the local off licence as i always got served without question.

3 Likes

To be fair, the same would’ve happened had you turned up with that blonde hair :slight_smile:

2 Likes

:joy:

1 Like

More likely

2 Likes

I must emphasise the fun you could have with this extension for those reading the comments. Of course there is also the serious aspect too! Great Extension Brian. I should have said this first before cracking jokes. Great thing about the Community is we can all have a laugh together. Always reminded what a fantastic hub this is and how lucky we all are to have such a fine and fun loving bunch of Users hanging around the place.

:smiling_face_with_three_hearts:

I’m feeling the luuurv on this post - I think the majority of us have a very similar type of outlook.

1 Like

You think those images were random or deliberately provocative. :rofl:

3 Likes

Off on a total tangent now...

I get Office type vibes here (the ORIGINAL series). I'd love to think of us all in the same office working alongside each other. Actually have a connection with Ricky Gervais as went to school with him although he was a year above me (our whole school was full of such characters as most of us were from rough Council estates and had to have a thick skin and sense of humor). I also know the real David Brent and am friends with his son (who used to frequent my old shop). Now my question is who would be who based on the Office cast....?

:laughing:

Can i be honest,never watched it, UK or US version. Was not a big fan of Gervais in his early days although i do like his later stuff.

What a nightmare that would be, we’d get absolutely NOTHING at all done har har har… We’d be too busy bantering.

I’ve never watched the office either :slight_smile:

1 Like

Actually i think a group of selected Wappler developers form here, working together to their strengths, could take on the world and do great things.

2 Likes

That’s a great concept - a collaboration on a project!! - A bit like Thunderbirds..

1 Like