In digital image processing (DIP), image scaling refers to the resizing of a digital image. If we are increasing the size of an image then it means that we are scaling it up and if we are decreasing or making the image the smaller, then it means we are scaling it down. Here, we are scaling an image using R Programming language.
Image in use:

Implementation of Image Scaling in R
In this section, we will be scaling our image using R programming language. We can do it using two methods.
Method 1: Using OpenImageR
We will install OpenImageR package which has various functions for image preprocessing, filtering and image recognition.
install.packages("OpenImageR")
The image to be resized is imported to the environment and the required resizing is done using image_scale() function. It is a helper function to draw scale for image. We will pass the image and the value as arguments in the function.
Syntax:
image_scale(img,"size")
The only difference in scaling up or down comes from the size value passed to image_scale() function. To scale up down pass a value smaller than 100 and to up scale a value greater than 100.
Example:
- library(OpenImageR): Loads the OpenImageR library, which provides functions for image processing.
- image_read("gfg.png"): Reads the image file "gfg.png" into the img object.
- image_scale(img, "30%"): Scales the image to 30% of its original size.
library(OpenImageR)
img = image_read("gfg.png")
image_scale(img,"30%")
Output :

Method 2: Using magick
magick is a package in R programming language that provides modern and simple toolkit for image processing. We will install magick package in our R environment.
install.packages("magick", dependencies = TRUE)
The process completely similar to the above method the difference the package. Here, image_scale() function can also be used to resize image here too and can be deal with height and width at the same time.
Syntax:
image_scale( image_scale (image, "width"), "height")
Example:
- library(magick): Loads the magick library, which is used for advanced image processing.
- image_read("gfg.png"): Reads the image file "gfg.png" into the img object.
- image_scale(img, "50%"): Scales the image to 50% of its original size.
- image_scale(image_scale(img, "50%"), "80%"): First scales the image to 50% and then scales it further to 80% of the new size (i.e., the resulting image is 40% of the original size).
library(magick)
img = image_read("gfg.png")
image_scale(image_scale(img,"50%"),"80%")
Output:
