Determine an image's primary point of interest with this custom operation, powered by OpenAI.
Speaker 0: The AI focal point detection operation uses AI to determine the point of interest inside of an image. You can combine this with Directus' new focal point functionality to make sure that as images are automatically cropped, or cropped via API requests that your points of interests are are not lost in that cropping. Otherwise, by default, it happens from the center. So that's what we're gonna set up today. We're gonna do this whenever a new file is uploaded.
So focal point. We're gonna do this whenever a new file is uploaded. So we will do files dot upload. This will run with every single file upload regardless of location, regardless of file types in the reel. You will want a condition just to check that this is indeed an image.
The documentation for this operation in the marketplace, the listing page, shows you how to set that up. For now, we're gonna assume every file needs this treatment applied to it. So we are gonna go in, and we are gonna use our AI focal point detection end point. Now this uses OpenAI. So we have to put in our open AI API key and a full file URL.
So first thing is our director's project URL, so that's mine, slash assets slash and then a dynamic value trigger dot key. That's the ID of the image that was uploaded and triggered this flow to actually start. So that will come back with an object, which contains a focal point x, a focal point y, and a reason. The reason could be interesting based on your use case. We're not gonna do anything with it.
Instead, we're just gonna update the directives files item, specifically the item that triggered this whole flow to start. And we are going to update the focal point x value to be the value that came from the last operation focal point x. We're gonna do the same for focal point y. And, again, you know, you may choose to do something, you may choose to do something with the reason, but we are not going to. So focal point y and with Jason no hanging commas.
That's the whole thing. That's how you use AI to set up focal points. It's really, really cool, and really leverages this new feature of Directus along with AI to just really make your media library a lot more expressive when you're using it in your actual applications. So let's try this out. I just uploaded a new image, that should have triggered that whole flow, the focal points to be, to be generated, and then save to that back to the focal point x and y value.
And there it is. Now you don't need to do anything more with these values. When you start to crop the image using URL parameters, using the on the fly media transformations that directors provide, that will be the central point which the image is cropped around. So I hope you found this interesting, and I'll see you in the next video.