code: def main(argv):
      del argv  # Unused.
      # TODO: Add more flag validations.
      if FLAGS.max_failures is not None and FLAGS.max_failures > 0:
          raise NotImplementedError(
              "Does not yet handle image retrieval/conversion "
              "failures"
          )
  
      if (
          FLAGS.atlas_width is not None
          or FLAGS.atlas_height is not None
      ):
          raise NotImplementedError(
              "Does not yet support specifying an atlas size."
          )
  
      if FLAGS.sourcelist is None:
          raise flags.ValidationError(
              "You must specify a list of image sources."
          )
  
      bg_color_rgb = _determine_bg_rgb()
  
      outputdir = FLAGS.output_dir
      if outputdir is None:
          outputdir = os.path.join(os.getcwd())
  
      image_source_list = atlasmaker_io.read_src_list_csvfile(
          FLAGS.sourcelist, FLAGS.sourcelist_dups_handling
      )
  
      # Provide some useful confirmation info about settings to user.
      logging.info(
          "Desired output size in pixels width, height for each image is: "
          "(%d, %d)" % (FLAGS.image_width, FLAGS.image_height)
      )
      logging.info("Image format for Atlas is: %s" % FLAGS.image_format)
      logging.info("Background RGB is set to %s" % str(bg_color_rgb))
      logging.info(
          "Background opacity is set to %d" % FLAGS.image_opacity
      )
      logging.info(
          "Should we preserve image aspect ratio during conversion? %s"
          % FLAGS.keep_aspect_ratio
      )
  
      image_convert_settings = convert.ImageConvertSettings(
          img_format=FLAGS.image_format,
          width=FLAGS.image_width,
          height=FLAGS.image_height,
          bg_color_rgb=bg_color_rgb,
          opacity=FLAGS.image_opacity,
          preserve_aspect_ratio=FLAGS.keep_aspect_ratio,
          resize_if_larger=FLAGS.resize_if_larger,
      )
  
      # Ensure we can write to the output dir or fail fast.
      atlasmaker_io.create_output_dir_if_not_exist(FLAGS.output_dir)
  
      # Create default image to be used for images that we can't get or convert.
      if FLAGS.default_image_path is not None:
          logging.info(
              "Using image %s as default image when a specified image "
              "can't be fetched or converted" % FLAGS.default_image_path
          )
          default_img = parallelize.convert_default_image(
              FLAGS.default_image_path, image_convert_settings
          )
      else:
          logging.info(
              "No default image for failures specified by user, so just "
              "using the background as the default image."
          )
          default_img = convert.create_default_image(
              image_convert_settings
          )
  
      # Verify we can write the specified output format, or fail fast.
      try:
          testimage_file_name = "{}.{}".format(
              "testimage", str(FLAGS.image_format).lower()
          )
          atlasmaker_io.save_image(
              default_img,
              os.path.join(FLAGS.output_dir, testimage_file_name),
              delete_after_write=True,
          )
          logging.info(
              "Confirmed we can output images in %s format"
              % FLAGS.image_format
          )
      except:
          logging.error(
              "Unable to write test image in desired output format. "
              "Please confirm that '%s' is a supported PIL output "
              "format." % FLAGS.image_format
          )
          raise
  
      # Convert images in parallel.
      logging.info("Scheduling %d tasks." % len(image_source_list))
      converted_images_with_statuses = (
          parallelize.get_and_convert_images_parallel(
              image_source_list,
              image_convert_settings,
              n_jobs=FLAGS.num_parallel_jobs,
              verbose=FLAGS.parallelization_verbosity,
              allow_truncated_images=FLAGS.use_truncated_images,
              request_timeout=FLAGS.http_request_timeout,
              http_max_retries=FLAGS.http_max_retries,
          )
      )
  
      sprite_atlas_settings = montage.SpriteAtlasSettings(
          img_format=FLAGS.image_format,
          height=FLAGS.atlas_height,
          width=FLAGS.atlas_width,
      )
  
      # Generate the atlas from converted images.
      sprite_atlas_generator = montage.SpriteAtlasGenerator(
          images_with_statuses=converted_images_with_statuses,
          img_src_paths=image_source_list,
          atlas_settings=sprite_atlas_settings,
          default_img=default_img,
      )
  
      atlases, manifests = sprite_atlas_generator.create_atlas()
  
      atlasmaker_io.save_atlas_and_manifests(
          outdir=outputdir,
          atlases=atlases,
          manifests=manifests,
          sprite_atlas_settings=sprite_atlas_settings,
      )
  
file_path: facets/facets_atlasmaker/atlasmaker.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import os
  from absl import app
  from absl import flags
  from absl import logging
  from PIL import ImageColor
  import atlasmaker_io
  import convert
  import montage
  import parallelize
label_desc: Use image node_id 2 for calling a global function with example usage: main(argv) without return types