This is a sample script for converting a range in Google Spreadsheet as an image data using Google Apps Script. Unfortunately, there are no methods for directly converting the range in Google Spreadsheet as an image data in the built-in functions. So in this case, as a workaround, Charts Service is used.
const range = "B5:D10";
const [header, ...values] = SpreadsheetApp.getActiveSheet()
.getRange(range)