Make Crazy Art with the NEW OpenAI Dall-e API

Beyond Fireship · Beginner ·🎨 Image & Video AI ·3y ago

Key Takeaways

Create AI art using OpenAI's Dall-e models with the new Image Generation API, programmatically with JavaScript or Python

Full Transcript

artificial image generation has been one of the biggest Trends in machine learning over the last year we've seen all kinds of crazy demos like ai's depiction of human evolution and there are now a bunch of different apps out there that allow you to convert text into images like the stable diffusion demo on hugging face however if you want to generate your own images programmatically you'll need to know a thing or two about deep learning and have the hardware to run these compute intensive models well at least that was the case until now because openai just released their image generation API based on their Dolly 2 models that means any developer can now easily generate high quality artificial art and in today's video you'll learn some of the scary things that this API is capable of and I'll throw out some random business ideas for you of apps you might want to create with it before we get started you'll first need an open AI account and you should know that this is a paid API however they give you 18 dollars in credits to get started when you run out of money it will cost you about two pennies per image or 50 images per dollar that's at the max resolution which is currently 1024 pixels it's pretty expensive but as the co-founder of openai Elon Musk would say you get what you pay for go ahead and generate an API key then let's open up vs code and start a new node.js project although you can also easily do this in Python I'll run npm init y to start a new node.js project then use npm install to add the openai SDK for JavaScript now I'm creating three different JavaScript files because I want to show you how to do three different things generate a new image edit an existing image with a mask and create a variation from a source image then finally I'm creating a directory to hold all the image results and you'll also want to go into your package Json and turn the type to module just so we can use es Imports in our code but before we write in the actual code here's a business idea you could build a SAS product that allows a blogger to upload an article then you automatically generate five or six images that go along with the context of that article you could even take an old public domain book like Joseph Conrad's Heart of Darkness create a bunch of AI illustrations and republish it as an illustrated novel now that you have some terrible ideas to get you going let's implement it in code first we'll need to to import the configuration and open API classes from the SDK we create a configuration with the API key and make sure not to expose this API key publicly and then initialize the SDK next I'm creating a variable for the prompt which is a description of the image you want to generate like a ship sailing through a river of fire in deep space and now we can use top level weight to make a call to the create image endpoint on openai it takes the prompt as the first argument as well as the number of images you want to generate and the resolution you can also pass a user ID here which allows open AI to identify abuse like if you have a user who keeps trying to generate boobs and wieners that API call will result in an image URL now that we have that URL we can navigate to it directly or better yet we can save the image to disk in this demo I'm using node 18 which gives me access to the native fetch API in node we can use it to fetch the image URL then we can set the result as a blob we'll need to turn that blob into a buffer which we can do with buffer from by awaiting the blobs array buffer that gives us a format that we can then write to disk with write file sync from the node file system API and now we can generate some art by opening the terminal and use node to run the generate.js file it takes about five to ten seconds to generate an art piece but overall the quality is pretty impressive the next thing I want to show you is how to create an image variation let's go ahead and copy all the code we just wrote and paste it into the variation file now just delete the middle part where we make the call to open AI we're going to replace this with a different API call called create image variation it takes an existing image as a starting point and creates a different result this endpoint doesn't take a prompt but instead takes an image as its input I'm using a picture of the Mona Lisa as that input we pass the image path to create read stream from node.js which is just a fancy way of opening the file then pass Arguments for the number of results and resolution we can now go ahead and run this script from the terminal and it will generate a different version of the Mona Lisa a much uglier one occasionally Dolly produces some really cool stuff but for the most part it's not very aesthetically pleasing I did some testing and recursively generated the Mona Lisa 25 times along with a bunch of other art and found that the algorithm leans towards cartoon characters like The Simpsons and stuff like that if you keep feeding its own results back to it it eventually just devolves into garbage because it's not really making art but rather combining the art made by millions of humans into something that looks like art at first in any case there's one more thing I want to show you and that's how to change a specific part of an existing image I think this aspect of the API has the most potential because you could use it to augment an existing image in more subtle and interesting ways to make something like this we'll first copy our code over to the edit file and this time replace the middle part with a call to the create image edit endpoint this endpoint requires two images one is the source of the full image and the second is a mask or an area of that same image that's transparent that will be replaced with something AI generated I'm using a picture of myself writing some code now the question becomes how do we create a mask there are many ways you could go about it but I'll show you how to do it in figma first we have the original image and now we have a duplicate of it and I'm using the pen tool to draw a shape around the area that I want to mask from there we can select both the image and the shape and then go up here and do subtract selection that should turn the shape white and then we'll also want to go and make sure that the frame does not have a background and then we can export it as a PNG into our project now if we go ahead and run the code we get an image back where only the computer screen has AI generated art that's pretty cool and I think there's a lot of potential for creativity here this concludes our openai Dolly tutorial thanks for watching and I will see you in the next one

Original Description

Learn how to create your own AI art with OpenAI's Dall-e models. The new Image Generation API was just announced yesterday allowing anybody to create images from text programmatically with JavaScript or Python. #tech #ai #programming OpenAI Docs https://beta.openai.com/docs/guides/images Preview App https://labs.openai.com
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Beyond Fireship · Beyond Fireship · 15 of 42

1 Social Media Style Number Formatting in JS
Social Media Style Number Formatting in JS
Beyond Fireship
2 I used 3 different File System APIs in Node.js
I used 3 different File System APIs in Node.js
Beyond Fireship
3 Time is Relative, even in JavaScript
Time is Relative, even in JavaScript
Beyond Fireship
4 How to NOT Screw Up Firebase Environment Variables
How to NOT Screw Up Firebase Environment Variables
Beyond Fireship
5 How to make your JavaScript Bundle Smaller
How to make your JavaScript Bundle Smaller
Beyond Fireship
6 Subtle, yet Beautiful Scroll Animations
Subtle, yet Beautiful Scroll Animations
Beyond Fireship
7 Beyond Surreal? A closer look at NewSQL Relational Data
Beyond Surreal? A closer look at NewSQL Relational Data
Beyond Fireship
8 How to Build a Discord Bot
How to Build a Discord Bot
Beyond Fireship
9 How to make Eyeballs that Follow You Around
How to make Eyeballs that Follow You Around
Beyond Fireship
10 Reverse Engineer Google’s NASA Dart Easter Egg with CSS
Reverse Engineer Google’s NASA Dart Easter Egg with CSS
Beyond Fireship
11 Generate Images Programmatically on the Edge
Generate Images Programmatically on the Edge
Beyond Fireship
12 WTF are all these config files for?
WTF are all these config files for?
Beyond Fireship
13 NEW Firebase Features Just Dropped
NEW Firebase Features Just Dropped
Beyond Fireship
14 Next.js 13 - The Basics
Next.js 13 - The Basics
Beyond Fireship
Make Crazy Art with the NEW OpenAI Dall-e API
Make Crazy Art with the NEW OpenAI Dall-e API
Beyond Fireship
16 How to Setup Node.js with TypeScript in 2023
How to Setup Node.js with TypeScript in 2023
Beyond Fireship
17 Dramatically improve website speed with Partytown
Dramatically improve website speed with Partytown
Beyond Fireship
18 The easiest realtime app I’ve ever built
The easiest realtime app I’ve ever built
Beyond Fireship
19 10 Rendering Patterns for Web Apps
10 Rendering Patterns for Web Apps
Beyond Fireship
20 You don't need Node to use NPM packages
You don't need Node to use NPM packages
Beyond Fireship
21 Sorting Algorithms Explained Visually
Sorting Algorithms Explained Visually
Beyond Fireship
22 ChatGPT Official API First Look
ChatGPT Official API First Look
Beyond Fireship
23 I built an image search engine
I built an image search engine
Beyond Fireship
24 Industrial-scale Web Scraping with AI & Proxy Networks
Industrial-scale Web Scraping with AI & Proxy Networks
Beyond Fireship
25 Next.js Server Actions...  5 awesome things you can do
Next.js Server Actions... 5 awesome things you can do
Beyond Fireship
26 The ultimate guide to web performance
The ultimate guide to web performance
Beyond Fireship
27 I built a fullstack PaLM AI app in just 2 minutes
I built a fullstack PaLM AI app in just 2 minutes
Beyond Fireship
28 I tried 8 different Postgres ORMs
I tried 8 different Postgres ORMs
Fireship
29 I built a *streaming* AI chat app
I built a *streaming* AI chat app
Fireship
30 React VS Svelte...10 Examples
React VS Svelte...10 Examples
Fireship
31 How GitHub Actions 10x my productivity
How GitHub Actions 10x my productivity
Fireship
32 PROOF JavaScript is a Multi-Threaded language
PROOF JavaScript is a Multi-Threaded language
Fireship
33 Mind-blowing page animations are easy now... View Transitions API first look
Mind-blowing page animations are easy now... View Transitions API first look
Fireship
34 I built an Apple Vision Pro app... visionOS tutorial
I built an Apple Vision Pro app... visionOS tutorial
Fireship
35 This UI component library is mind-blowing
This UI component library is mind-blowing
Fireship
36 How I deploy serverless containers for free
How I deploy serverless containers for free
Fireship
37 GitHub Copilot now controls your command line...
GitHub Copilot now controls your command line...
Fireship
38 Build better payment forms using new “embedded” Stripe Checkout
Build better payment forms using new “embedded” Stripe Checkout
Fireship
39 Does Deno 2 really uncomplicate JavaScript?
Does Deno 2 really uncomplicate JavaScript?
Fireship
40 JavaScript performance is weird... Write scientifically faster code with benchmarking
JavaScript performance is weird... Write scientifically faster code with benchmarking
Fireship
41 Is Next.js 15 any good? "use cache" API first look
Is Next.js 15 any good? "use cache" API first look
Beyond Fireship
42 I built a DeepSeek R1 powered VS Code extension…
I built a DeepSeek R1 powered VS Code extension…
Fireship

Learn how to create AI art with OpenAI's Dall-e models using the new Image Generation API, allowing for programmatic image generation with JavaScript or Python. This API enables users to generate images from text, opening up new possibilities for creative applications. By following this lesson, users can create their own crazy AI art and explore the capabilities of the Dall-e models.

Key Takeaways
  1. Sign up for an OpenAI account
  2. Explore the OpenAI Docs for image generation
  3. Choose a programming language (JavaScript or Python)
  4. Use the Image Generation API to generate images from text
  5. Experiment with different prompts and parameters
  6. Refine and iterate on generated images
💡 The OpenAI Dall-e models can generate highly realistic and diverse images from text prompts, allowing for a wide range of creative applications

Related Reads

📰
Topaz Gigapixel Review 2026: The Upscaler Is Good, But Not Magic
Learn the limitations of AI upscaling tools like Topaz Gigapixel and how they differ from real image information
Medium · AI
📰
Building a color replacer: why RGB matching fails on photos and how HSV fixes it
Learn why RGB matching fails for color replacement in photos and how HSV can fix it, improving your image processing skills
Dev.to · Irrational Apps
📰
I Built an Image Steganography Tool — Hide Any File Inside a PNG with AES-256 Encryption
Learn to build an image steganography tool that hides files inside PNGs with AES-256 encryption, enhancing security and privacy
Dev.to · Rishu
📰
Histogram-constrained Image Generation
Learn to generate images with histogram constraints using diffusion models for better control over output
ArXiv cs.AI
Up next
OpenAI Kills Sora then Descends into Chaos
ColdFusion
Watch →