Saving images
You have already learned how to load and download images, so now it's time to learn how to save your image. We will use the save
function from the Images
package to save the image to disk.
The save
function accepts two arguments:
- The destination file location and name
- The image object
Let's have a look at the code to save images:
# load an image img = load("sample-images/cats-3061372_640.jpg") # save file in JPG format save("my_new_file.jpg", img) # save file in PNG format save("my_new_file.png", img)
The image format is chosen based on the filename extension. Please note that saving the image in different formats can affect the output quality and file size. Users should find a balance between size and quality.
The save
function does not allow you to set image quality, which is usually available in graphics editors, such as GIMP.