Using image URL in images/edits request

There is another recent post in the community that may relevant. It talks about the file being 24 bit vs 32 bit PNG files.

My understanding is that the file.name setting in my example above is important in Typescript. It helps the AI understand that it is a valid PNG file. I suspect you may need to give your image and mask buffers names, and also cast them as type any

1 Like

didnt mean to tag you in that last reply, sorry raymon. thanks for the help, but it isn’t working for me sadly

1 Like

Do you have your code with the changes made?

Screenshot_1

image

i’m not even getting a useful error message anymore

Can you cast while calling a function?

I would set it up like one of the two examples above…

Also, you’re not setting image.name so it’s certain it’s a PNG… might be the problem?

more of the same. here’s all my code in one spot.


Screenshot_3

Can you upload the image and mask you’re using?

Are they 24bit or 32bit PNGs?

Is the normal generation endpoint working for you?

ETA: Might also try casting and setting up the images within the function?

1 Like

Can you also give us the console.log output for the response object (remove any sensitive info first)

If that is what is in the second image you posted, then response is undefined at the time the log is being called

1 Like

generation works. i’m using a function to save the generation response as a PNG, then using that as my edits image. i’m not sure if it’s 24b or 32b, but i’ll dig into it.

i do have some console logs in my code, but it seems they aren’t even triggering. i’m getting some massive block of data from the API, and the second image is what i can gather as the relevant part of it. i think it’s returning undefined because something is wrong with my request. hopefully it’s the bits thing.

I’m betting that might be something to do with it?

What are you using to save the PNG?

i’m using the npm library ‘image-downloader’

image

I’m starting to think maybe it’s not saving the PNG correctly…or rather, not saving in a form DALLE2 can use…

Can you upload the image and mask you’re using?

Might also try to return it as base64 rather than url…

Can you give us an example of what you get for the url variable?

Is it a url, or is it a string starting with “data:image/gif;base64,R0l” etc…

If it is undefined, can you also get the value for response.data[0][“url”]
Note: this only has one reference to data

I have some ideas - but the answer will help go in the right direction

Finally, can you also give the line where you define the download object in your final bit of code

https://oaidalleapiprodscus.blob.core.windows.net/private/org-iXQ5jPan1aYIFVj3pQgfwLh5/user-gGYciXCncqKJKkTnlOPE8Vpb/img-RA5juSiEiSrYwzvw3VmOz7PL.png?st=2023-01-12T00%3A40%3A55Z&se=2023-01-12T02%3A40%3A55Z&sp=r&sv=2021-08-06&sr=b&rscd=inline&rsct=image/png&skoid=6aaadede-4fb3-4698-a8f6-684d7786b067&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2023-01-11T23%3A39%3A44Z&ske=2023-01-12T23%3A39%3A44Z&sks=b&skv=2021-08-06&sig=zhtFqp3gdVZWWBFSOqvXDDYQNBYlfjuk56sfhViwNeE%3D

this is a URL returned by my request to image generations. i’ve tried many different ways of converting both URL and b64 data to a valid PNG, but i had no idea what exactly constitutes such a thing. so i eventually ended up on the npm package ‘image-installer’, which is where the download object is from.

import * as download from 'image-downloader'

as for using b64 @PaulBellow, i’m just not certain how exactly to convert it to a valid PNG. i’ve tried several methods but haven’t landed on the right way. i knew absolutely nothing about images before this project, so it’s tough for me to identify where the issues are coming from

i tried logging the url response from edits, but it doesn’t even trigger the log. the call fails and logs a huge object that i’m not familiar with

image

OK, so you are getting the image url back (excellent)

It is a url, so we need to download the url and save it locally as a PNG file (At least that will get you able to move forward)

You need to use the variable “url” instead of “image” (Assuming the output you gave me above was from the url variable)

I also assume the path …/…/images can be accessed by your code when it is running. Try removing the …/…/images prefix if this doesn’t work.


const download = require(‘image-downloader’);

options = {
url: url,
dest: ‘…/…/images/cover.png’,
};

download.image(options)
.then(({ filename }) => {
console.log(‘Saved to’, filename);
})
.catch((err) => console.error(err));

1 Like

image i’ll try tweaking the path

I didnt see your final message before I replied

Try url = response.data[0][“url”]

Also wrap it all in a try/catch block and see if you are getting an exception

well, this is working fine. i have the image saved locally after running it. i forgot to mention that

1 Like

I’ll message you directly to avoid filling up the chat. We can post the final answer here

1 Like