Join Carmen as we assign our transformations to presets that we can apply to multiple images.
Speaker 0: Hello, everybody. My name is Carmen, and welcome to Sharp Focus, the show where we create a beautiful framing of how Directus allows you to transform your images and truly make them shine. Now in the last 4 episodes, gosh, they've gone by so quickly, we've seen how we can manipulate, create optimizations for, and apply advanced transformations of all of our images in direct Us. But getting to do so becomes a little bit cumbersome if you have to repeat yourself all the time. So in this final episode, we're gonna look at how you can create presets in Direct Us and just quickly grab those keys up and apply them to your images all in one go.
And it's gonna be a lot of fun. So I hope you've got your cameras handy. I've got mine. Let's look into how we can apply those presets in Directus. Here we are in my Directus project dedicated to my photography, and we'll be looking at the final photo from my trip to Chile, La Capilla de Marmol or Marble Chapels located in the south of Chile in the Lake General Carrera, which is just beautiful, but I digress.
So as much power and control as these custom and advanced transformations offer us, having to specify them every time we want to retrieve an image can become cumbersome. So what we can do is save presets that we can then later reference and think of this as a collection of transformations that we can then specify and apply at once. Now Directus actually comes with one of these built in, which I would like to show you now. In my code for my Nuxt app, you can see that I'm specifying a key and system large contain. And this is a built in preset that then shows the image in a nice large way that is contained.
Fantastic. But how can we build our own? Let's go over to our settings module and its according settings section. And we're gonna scroll down here to our transformation presets. And we're gonna go ahead and click on create new.
Now let's call this cool thumbnail. Naming was never really my thing. And now you're going to recognize a lot of these transformations that we've been using throughout this series. So let's go with contain, a width of 300, a height of 500. We will leave the upscaling as is, and our format is gonna be JPEG.
We're not gonna do any advanced transformations for now using Sharp, and we're gonna go ahead and save that. Now that that's done and saved, let's go back to our application and start using it. So we've got our ID specified already, and we're gonna replace our key with, as said, cool thumbnail. Go ahead and save that. And now we're going to see, We've applied our preset all in one go.
And now the great thing about this is that these transformations can be applied not just as the SDK level, but of course at a rest level. So if we wanted to go to that URL, put in our ID, and specify as a query parameter the key cool thumbnail, there's our cropped and resized image. That's how we can create and utilize presets of several transformations in one go. Alright, folks. Well, that's it.
The last photoshoot is done. It's like we've taken everything we've learned in the last 4 episodes and culminated into one big preset that we can use time and time again without having to write out all of these transformations. So now we can optimize, we can manipulate, and we can apply advanced transformations to our images using Directus. So that ends series 1 of Sharp Focus. Thank you so much for watching.
If you have any lingering doubts or wanna explore what else you can do with Directus, be sure to check out our documentation and check out the Directus community. But that's it for now. I will say, once again, thanks for watching. Remember, keep those cameras handy, and I will see you in the next episode. Bye for now.