Join Carmen as we transform our images to be more performant and format-conscious.
Speaker 0: Hello, everybody. My name is Carmen, and welcome to Sharp Focus, the show where we zoom in on how Directus allows you to transform your images and truly make them shine. Now in previous episodes, we've seen how Directus stores your images and how you can grant permission and access to them. And we've also seen how you can manipulate your images width and height and fit using the Directus SDK and REST API. So what's next?
In this episode, we're going to focus on size and performance. If you're working with a lot of images, you wanna keep some consistency and focus on the user experience, making sure that the images are consistently sized, but more importantly, load quickly. So let's find out how Directus does that for you. Let me just grab my camera, and let's hop right in. All right.
Here we are in my directest project dedicated to my photography. And once again, we're going to be looking at my photos from my trip to Chile. In this episode, we're going to be working with the photos of the geysers del Tapio, which are located in the Andes mountains of Northern Chile. And these are beautiful geysers that we're going to be working with. So I said in this episode, we're going to be focusing on the size and performance of transforming our images.
Let's again, look at our Nuxt app, which has now been modified to also show the size of our image here, clocking in at 46 kilobytes. Now over in our code, we've got our width, our height, and our fit as we saw in the image manipulations of episode 2. Our first parameter that we're gonna be working with is quality, which can take a value of 0 to 100. The higher the value, the higher the quality, but let's see what happens when we go lower in quality. I'm gonna start with 50%.
So we can see the file has been reduced to 26 kilobytes and the image looks a little bit rougher, but not too bad. Let's bring it a little lower, half that to 25. We're seeing a file size of 16 kilobytes and the image looks a little bit grainier. If I bring that down to 5%, we're gonna see the image gets even lower in quality. It becomes a little difficult to see our beautiful geysers, but the image size is 4 kilobytes.
And if I bring it all the way to a 100%, we're gonna see the image looks beautiful, but the size is a 153 kilobytes. So let's leave it at that 80% sweet spot. Next, we'll look at the format attribute. Its value will modify the format of the image. So we have the options of auto, JPEG, PNG, webp, and tiff.
So if we start with auto, which is a default value, directives will try to format it in webp or avif depending on browser support. Otherwise, it'll fall back to JPEG. Let's look at JPEG PNG. We'll see that our image now has a size of a 111 kilobytes. If we try and web peak, we'll see 43 kilobytes.
Let's leave that with auto by default. And finally, we'll have a look at the without enlargement property, which defaults to true. So if we set that to false, Directus will not upscale the image. So now I have a lot more granular control over the sizing of my images when I use them in my applications. All right.
Well, there you have it folks. We've seen how we can use the direct to SDK to manipulate the quality and the format and the upscaling of our images. And as you can see, it's super straightforward and split fast. So what's next in the next episode, we're really going to dive into the sharp API and get into all of the nitty gritty advanced transformation. This one's super exciting folks.
So I'm looking forward to seeing you there. Just remember, keep your camera handy and I'll see you in the next one.