ae_movie_export_image.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. from tools import tools
  2. from tools import image_trimmer
  3. version = 1
  4. class MyTools(tools.Tools):
  5. def _initialize(self):
  6. self.add_argument_file('--in_path', 'in_path')
  7. self.add_argument_file('--out_path', 'out_path', exists=None)
  8. self.add_argument_dir('--export_path', 'export_path', exists=None)
  9. self.add_argument('--export_name', 'export_name')
  10. self.add_argument('--project_name', 'project_name')
  11. self.add_argument('--write_name', 'write_name')
  12. self.add_argument('--write_path', 'write_path')
  13. self.add_argument_integer('--image_border', 'image_border')
  14. self.add_argument_bool('--image_bezmesh', 'image_bezmesh')
  15. self.add_argument_bool('--image_trackmatte', 'image_trackmatte')
  16. self.add_argument_bool('--image_premultiplied', 'image_premultiplied')
  17. self.add_argument_bool('--out_premultiplied', 'out_premultiplied')
  18. self.add_argument_bool('--use_sha1', 'use_sha1')
  19. pass
  20. def _run(self, args):
  21. sha1path = None
  22. if args.use_sha1 is True:
  23. image_ext = self.get_ext(args.in_path)
  24. sha1hex, sha1path = self.get_file_sha1_new_path(args.in_path, image_ext)
  25. sha1params = dict(version=version
  26. , image_bezmesh=args.image_bezmesh
  27. , image_trackmatte=args.image_trackmatte
  28. , image_premultiplied=args.image_premultiplied
  29. , out_premultiplied=args.out_premultiplied
  30. , image_border=args.image_border)
  31. sha1tag = "export_image {}".format(sha1params)
  32. temp_path = self.get_sha1_cach_path(sha1tag, sha1hex + ".export_image")
  33. if args.out_path is not None:
  34. out_path = args.export_path + ".store_images" + "/" + sha1path
  35. pass
  36. else:
  37. out_path = None
  38. pass
  39. pass
  40. else:
  41. temp_path = self.get_temp_path("export_image.info")
  42. out_path = args.out_path
  43. pass
  44. if args.use_sha1 is False or ((args.out_path is not None and self.exist_file(out_path) is False) or self.exist_file(temp_path) is False):
  45. if out_path is not None:
  46. self.make_dir_for_file(out_path)
  47. pass
  48. if args.image_trackmatte is True and args.image_border == 0:
  49. args.image_border = 1
  50. pass
  51. premultiplied = args.image_premultiplied is False and args.out_premultiplied is True
  52. rv, info = image_trimmer.image_trimmer(args.in_path, dest_path = out_path, trim = (args.image_bezmesh is False), border = args.image_border, premultiplied = premultiplied)
  53. if rv != image_trimmer.ERROR_OK:
  54. error_message = image_trimmer.get_error_message(rv)
  55. print(error_message)
  56. return False
  57. pass
  58. base_width = info[0]
  59. base_height = info[1]
  60. trim_width = info[2]
  61. trim_height = info[3]
  62. offset_x = info[4]
  63. offset_y = info[5]
  64. with open(temp_path, "w") as f:
  65. f.write("{0}\n".format(base_width))
  66. f.write("{0}\n".format(base_height))
  67. f.write("{0}\n".format(trim_width))
  68. f.write("{0}\n".format(trim_height))
  69. f.write("{0}\n".format(offset_x))
  70. f.write("{0}\n".format(offset_y))
  71. pass
  72. pass
  73. else:
  74. with open(temp_path, "r") as f:
  75. base_width = f.readline().rstrip('\n')
  76. base_height = f.readline().rstrip('\n')
  77. trim_width = f.readline().rstrip('\n')
  78. trim_height = f.readline().rstrip('\n')
  79. offset_x = f.readline().rstrip('\n')
  80. offset_y = f.readline().rstrip('\n')
  81. pass
  82. pass
  83. if out_path is not None:
  84. print("out_path = {0}\n".format(out_path))
  85. pass
  86. print("base_width = {0}\n".format(base_width))
  87. print("base_height = {0}\n".format(base_height))
  88. print("trim_width = {0}\n".format(trim_width))
  89. print("trim_height = {0}\n".format(trim_height))
  90. print("offset_x = {0}\n".format(offset_x))
  91. print("offset_y = {0}\n".format(offset_y))
  92. if args.write_name is not None:
  93. if args.use_sha1 is True:
  94. print("write_name = {0}\n".format(sha1path))
  95. else:
  96. print("write_name = Movies2_{0}_{1}_{2}\n".format(args.export_name, "Image", args.write_name))
  97. pass
  98. pass
  99. if args.use_sha1 is True:
  100. image_write_path = sha1path
  101. pass
  102. else:
  103. image_write_path = args.write_path
  104. pass
  105. if image_write_path is not None:
  106. print("write_path = {0}\n".format(image_write_path))
  107. pass
  108. if args.image_premultiplied is False and args.out_premultiplied is True:
  109. print("premultiplied = 1\n")
  110. pass
  111. return True
  112. pass
  113. pass
  114. tools.run(MyTools)