1 00:00:00,300 --> 00:00:06,810 In this lecture, we're going to load an image into a library called Image in the resource section of 2 00:00:06,810 --> 00:00:10,350 this lecture, I provide a link to a create called image. 3 00:00:10,770 --> 00:00:14,460 This great exports functions for manipulating images. 4 00:00:14,790 --> 00:00:19,290 We're going to use it to help us apply a grayscale effect to an image. 5 00:00:19,830 --> 00:00:24,600 Technically, we don't need this package as long as we have the binary data. 6 00:00:24,720 --> 00:00:29,100 We can change in images appearance by modifying the binary data. 7 00:00:29,430 --> 00:00:33,300 It's an advanced topic which won't be covered in this course. 8 00:00:33,600 --> 00:00:38,790 It's going to be simpler to use a crate for interacting with images binary data. 9 00:00:39,150 --> 00:00:41,280 Let's copy the insulation code. 10 00:00:43,760 --> 00:00:47,090 Next, open the cargo configuration file. 11 00:00:49,630 --> 00:00:53,620 Lastly, paste the crate below the dependences table. 12 00:00:54,950 --> 00:00:55,700 Hey, everyone. 13 00:00:55,760 --> 00:00:56,990 It's me from the future. 14 00:00:57,200 --> 00:00:59,480 The image crate was recently updated. 15 00:00:59,720 --> 00:01:05,239 Unfortunately, this update will produce errors in our project to prevent these errors. 16 00:01:05,300 --> 00:01:11,420 I highly recommend using the same version in my video, which is zero point two three point one four 17 00:01:11,660 --> 00:01:15,620 versions, zero point two four or higher will cause problems. 18 00:01:15,920 --> 00:01:17,810 All right back to the video. 19 00:01:18,680 --> 00:01:20,780 Time to start loading the image. 20 00:01:21,020 --> 00:01:22,730 Open the library file. 21 00:01:25,300 --> 00:01:30,790 At the top of the file, we're going to import a function called image load from memory. 22 00:01:33,310 --> 00:01:38,110 The load from memory function will store a copy of the image for manipulation. 23 00:01:38,440 --> 00:01:43,690 The goal is to pass our binary data onto the image library for processing. 24 00:01:44,020 --> 00:01:46,750 Let's give it a try inside our function. 25 00:01:46,870 --> 00:01:49,900 We're going to create a variable called image. 26 00:01:50,170 --> 00:01:53,260 Its value will be the load from memory function. 27 00:01:55,780 --> 00:02:01,690 We can hover our mouse over at this function to learn about the type of value accepted by the function. 28 00:02:02,050 --> 00:02:05,680 It wants to borrow an array or a vector of binary data. 29 00:02:06,040 --> 00:02:09,520 Luckily, the decode function returns a vector. 30 00:02:09,789 --> 00:02:15,880 We can pass on the base 64 to vector variable to the function with the ampersand character. 31 00:02:18,290 --> 00:02:20,960 Next, we need to unwrap the value. 32 00:02:21,090 --> 00:02:27,590 If we look at the description again, the description states see return value has a type of image results. 33 00:02:27,920 --> 00:02:31,610 The image result type is a variation of the result type. 34 00:02:31,940 --> 00:02:35,780 We can change the unwrap function to grab the successful results. 35 00:02:38,350 --> 00:02:42,160 Next, let's call the log function with the following message. 36 00:02:42,410 --> 00:02:43,390 Image loaded. 37 00:02:45,920 --> 00:02:47,690 Time to give our app a test. 38 00:02:48,020 --> 00:02:51,650 If we did everything right, we could see the image get loaded. 39 00:02:51,950 --> 00:02:53,780 Try uploading a small file. 40 00:02:54,080 --> 00:02:56,780 I don't recommend uploading large files. 41 00:02:56,990 --> 00:03:00,500 The larger the file, the more processing power it'll take. 42 00:03:00,830 --> 00:03:03,740 The response from our application will take a while. 43 00:03:04,010 --> 00:03:08,420 If the response takes a while, I recommend using a smaller file. 44 00:03:11,090 --> 00:03:14,120 After a few seconds, the image has been loaded. 45 00:03:14,390 --> 00:03:18,050 We can move on to changing the colors of the image with rust. 46 00:03:18,380 --> 00:03:21,050 Let's handle this action in the next lecture.