In this episode, we're focusing on resizing (cropping) images on the backend after a user uploads and selects a crop region for their profile photo. First, we walk through the directory where temporary uploads are stored and clear things out to start with a clean slate.
Next, we install and use an image manipulation package that lets us load the uploaded image from disk, crop it according to the regions the user selected (using width, height, x, and y values), and then save it back to the same temporary location. This part is where all the actual "backend magic" happens—the user adjusts the crop on the frontend, and we physically change the file on the server accordingly.
After showing how the cropping works by uploading and cropping an image, we check the temp directory to see that our changes are applied. We also discuss what happens next: although the cropped image is in the temporary directory for now, it shouldn't be moved to its final, public location until the user saves the form. That way, if the user isn't happy with the crop or cancels, nothing gets saved accidentally.
Finally, we set things up for the next episode, where we’ll look at dispatching the cropped image and saving it alongside the form submission.