hello and welcome to red stapler channel this video we are going to show
you a very useful service to generate a human photo using AI so you don't have
to worry at all when using it also how to use a free API to dynamically
generate photos with JavaScript ready let's check it out so let's start with
goto generated photos website then click browse photos
these photos are all pre-generated with AI
for each image you can pick the background color
unfortunately for transparent background and high resolution photos, you'll need to
purchase thier plan or buy each photo separately for one dollar anyway you can
use the image for free but you also need to add credit link to generated photos
website when using it you can also customize the filters such as gender
age hair and eye color etc now if you plan to use these images to let's say
populate a mock-up database you might want to use their API just create a free
account and go to the dashboard you get the API key for access the free plan
allows you to make a 500 API requests per month which should be enough for
personal project making API request is very easy you will only need to pass the
API key in header and make it get request to the provided base URL you can
also add parameters like numbers of returned photos gender age hair color
etc and response will be in JSON format with the URL of the images let's work on
the example first I'm going to create asynchronous JavaScript function called
getFace I will use a JavaScript fetch to make an API request I'll copy URL
provided in a dashboard
then set the request method to get and provide the API key in the authorization
header then we receive the respond and parse it using JSON method and put it on
console so you can see the structure. The API will provide for a different size of
the image now I'm going to create an empty image element then I'll set the
source to returned image URL
we can extract the URL from JSON like this
and that's all for this video if you want to see more web development tips
and tutorials subscribe our channel to stay tuned thanks for watching see you
next time bye