I am using the Stable Diffusion API for image generation, one of whose parameters is an image I will have to pass in as an URL string.
For example, if I want to use the image of a monkey, I can use
url: 'https://media.npr.org/assets/img/2017/09/12/macaca_nigra_self-portrait-3e0070aa19a7fe36e802253048411a38f14a79f8-s1100-c50.jpg'
However, I plan on using some images (PNG format) that I have stored in my local repository instead. Is there a quick possible way, or library (preferably in JavaScript) that allows me to dynamically generate an URL for the image? Thanks
Yes, when hitting the img2img endpoint of the stable diffusion API, the
init_imageparameter in the request body takes the image URL. Initially, I thought using theURL.createObjectURL()method in JavaScript to generate a temporary blob URL for local files would be the quickest way.So I wrote a
.htmlfile:When I uploaded an image and clicked on the Generate button, I got the following error in the console:
{"status":"error","messege":"Invalid init_image URL"}However, when I stored a image URL from the internet in the
imageURLvariable and ran clicked on the Generate button, the API request was successful. Similarly, if I upload my local image to a cloud platform and use its public URL and store it in theimageURLvariable, the API request is successful.Thus, the Stable Diffusion API requires an image URL that's accessible from the internet, not a local blob URL. If you want to use a local image, the quickest way actually seems to be to upload it to a server or an image hosting service and use its internet-accessible URL. There are several platforms and services you can use to host images. Some common options for you would be: Imgur, Cloudinary, GitHub Pages, and Google Drive. Some of these options actually allows to do uploads programmatically which would be efficient in the long run.