100 lines
3.8 KiB
Python

import core.contentGen as contentGen
import core.posterGen as posterGen
import core.simple_collage as simple_collage
import json
class poster_gen_config:
def __init__(self, json_file):
self.json_file = json_file
def get_info_directory(self):
return self.json_file['info_directory']
def get_poster_num(self):
return self.json_file['poster_num']
def get_input_dir(self):
return self.json_file['input_dir']
def get_target_size(self):
return self.json_file['target_size']
def get_output_dir(self):
return self.json_file['output_dir']
def get_tweet_content(self):
return self.json_file['tweet_content']
def generate_poster(poster_gen_config):
info_directory = poster_gen_config.get_info_directory()
poster_num = poster_gen_config.get_poster_num()
input_dir = poster_gen_config.get_input_dir()
target_size = poster_gen_config.get_target_size()
output_dir = poster_gen_config.get_output_dir()
tweet_content = poster_gen_config.get_tweet_content()
content_gen = contentGen.ContentGenerator()
response = content_gen.run(info_directory, poster_num, tweet_content)
# print(response)
img_list = simple_collage.process_directory(input_dir, target_size=target_size, output_count=poster_num, output_dir=output_dir)
poster_gen = posterGen.PosterGenerator()
poster_config = posterGen.PosterConfig(response)
result_path = []
for index, item in enumerate(poster_config.get_config()):
text_data = {
"title": f"{item['main_title']}",
"subtitle": "",
"additional_texts": [
{"text": f"{item['texts'][0]}", "position": "bottom", "size_factor": 0.5},
{"text": f"{item['texts'][1]}", "position": "bottom", "size_factor": 0.5}
]
}
img_path = img_list[index]['path']
print(img_path)
result_path.append(poster_gen.create_poster(img_path, text_data, f"{index}.jpg"))
return result_path
def main():
json_file_path = "/root/autodl-tmp/TravelContentCreator/poster_gen_config.json"
with open(json_file_path, 'r') as f:
json_file = json.load(f)
poster_config = poster_gen_config(json_file)
generate_poster(poster_config)
# info_directory = [
# "/root/autodl-tmp/sanming_img/相机/甘露寺/description.txt"
# ]
# poster_num = 1
# tweet_content = """
# """
# input_dir = "/root/autodl-tmp/sanming_img/modify/甘露寺"
# output_dir = "/root/autodl-tmp/poster_generate_result"
# target_size = (900, 1200)
# result_path = []
# content_gen = contentGen.ContentGenerator()
# response = content_gen.run(info_directory, poster_num, tweet_content)
# print(response)
# img_list = simple_collage.process_directory(input_dir, target_size=target_size, output_count=poster_num, output_dir=output_dir)
# print(img_list)
# poster_gen = posterGen.PosterGenerator()
# poster_config = posterGen.PosterConfig(response)
# # config_path = "/root/autodl-tmp/poster_generate_result/2025-04-17_09-31-03.json"
# # poster_config = posterGen.PosterConfig(config_path)
# for index, item in enumerate(poster_config.get_config()):
# text_data = {
# "title": f"{item['main_title']}",
# "subtitle": "",
# "additional_texts": [
# {"text": f"{item['texts'][0]}", "position": "bottom", "size_factor": 0.5},
# {"text": f"{item['texts'][1]}", "position": "bottom", "size_factor": 0.5}
# ]
# }
# img_path = img_list[index]['path']
# print(img_path)
# result_path.append(poster_gen.create_poster(img_path, text_data, f"{index}.jpg"))
if __name__ == "__main__":
main()