In this lecture, we're going to load an image into a library called Image in the resource section of
this lecture, I provide a link to a create called image.
This great exports functions for manipulating images.
We're going to use it to help us apply a grayscale effect to an image.
Technically, we don't need this package as long as we have the binary data.
We can change in images appearance by modifying the binary data.
It's an advanced topic which won't be covered in this course.
It's going to be simpler to use a crate for interacting with images binary data.
Let's copy the insulation code.
Next, open the cargo configuration file.
Lastly, paste the crate below the dependences table.
Hey, everyone.
It's me from the future.
The image crate was recently updated.
Unfortunately, this update will produce errors in our project to prevent these errors.
I highly recommend using the same version in my video, which is zero point two three point one four
versions, zero point two four or higher will cause problems.
All right back to the video.
Time to start loading the image.
Open the library file.
At the top of the file, we're going to import a function called image load from memory.
The load from memory function will store a copy of the image for manipulation.
The goal is to pass our binary data onto the image library for processing.
Let's give it a try inside our function.
We're going to create a variable called image.
Its value will be the load from memory function.
We can hover our mouse over at this function to learn about the type of value accepted by the function.
It wants to borrow an array or a vector of binary data.
Luckily, the decode function returns a vector.
We can pass on the base 64 to vector variable to the function with the ampersand character.
Next, we need to unwrap the value.
If we look at the description again, the description states see return value has a type of image results.
The image result type is a variation of the result type.
We can change the unwrap function to grab the successful results.
Next, let's call the log function with the following message.
Image loaded.
Time to give our app a test.
If we did everything right, we could see the image get loaded.
Try uploading a small file.
I don't recommend uploading large files.
The larger the file, the more processing power it'll take.
The response from our application will take a while.
If the response takes a while, I recommend using a smaller file.
After a few seconds, the image has been loaded.
We can move on to changing the colors of the image with rust.
Let's handle this action in the next lecture.