code: def convert_image(args):
      file_name = args[0]
      source_dir = args[1]
      dest_dir = args[2]
      width = args[3]
      height = args[4]
      mode = args[5]
      ch = args[6]
  
      src_file_name = os.path.join(source_dir, file_name)
      file_name = os.path.splitext(file_name)[0] + ".png"
      dest_file_name = os.path.join(dest_dir, file_name)
      dest_path = os.path.dirname(dest_file_name)
      # print(src_file_name, dest_file_name)
  
      # open source image
      try:
          im = imread(src_file_name)
          if len(im.shape) < 2 or len(im.shape) > 3:
              logger.warning(
                  "Illegal image file format %s.".format(src_file_name)
              )
              raise
          elif len(im.shape) == 3:
              # RGB image
              if im.shape[2] != 3:
                  logger.warning("The image must be RGB or monochrome.")
                  csv_data.remove(data)
                  raise
  
          # resize
          h = im.shape[0]
          w = im.shape[1]
          # print(h, w)
          if w != width or h != height:
              # resize image
              if mode == "trimming":
                  # trimming mode
                  if float(h) / w > float(height) / width:
                      target_h = int(float(w) / width * height)
                      # print('crop_target_h', target_h)
                      im = im[
                          (h - target_h) // 2 : h - (h - target_h) // 2,
                          ::,
                      ]
                  else:
                      target_w = int(float(h) / height * width)
                      # print('crop_target_w', target_w)
                      im = im[
                          ::,
                          (w - target_w) // 2 : w - (w - target_w) // 2,
                      ]
                  # print('before', im.shape)
              elif mode == "padding":
                  # padding mode
                  if float(h) / w < float(height) / width:
                      target_h = int(float(height) / width * w)
                      # print('padding_target_h', target_h)
                      pad = (
                          (
                              (target_h - h) // 2,
                              target_h - (target_h - h) // 2 - h,
                          ),
                          (0, 0),
                      )
                  else:
                      target_w = int(float(width) / height * h)
                      # print('padding_target_w', target_w)
                      pad = (
                          (0, 0),
                          (
                              (target_w - w) // 2,
                              target_w - (target_w - w) // 2 - w,
                          ),
                      )
                  if len(im.shape) == 3:
                      pad = pad + ((0, 0),)
                  im = np.pad(im, pad, "constant")
                  # print('before', im.shape)
              im = imresize(im, size=(width, height))
              # print('after', im.shape)
  
          # change color ch
          if len(im.shape) == 2 and ch == 3:
              # Monochrome to RGB
              im = np.array([im, im, im]).transpose((1, 2, 0))
          elif len(im.shape) == 3 and ch == 1:
              # RGB to monochrome
              im = np.dot(im[..., :3], [0.299, 0.587, 0.114]).astype(
                  np.uint8
              )
  
          # output
          try:
              os.makedirs(dest_path)
          except OSError:
              pass  # python2 does not support exists_ok arg
  
          imsave(dest_file_name, im)
      except:
          logger.warning("Failed to convert %s." % (src_file_name))
  
file_path: nnabla/python/src/nnabla/utils/cli/create_image_classification_dataset.py
imports: import csv
  import multiprocessing
  import os
  import re
  import nnabla.logger
  import numpy
  import tqdm
  from nnabla.utils.image_utils import imsave, imread, imresize
label_desc: Use image node_id 1 for calling a global function with example usage: convert_image(args) without return types