Files
image_editor/Image_Editor.py
2026-05-07 17:22:56 +09:00

330 lines
14 KiB
Python

# --- package ---
# --- custom_module ---
import sys
# 20260507 tak will be check
#sys.path.append('C:/Users/Administrator/PycharmProjects/pythonProject/20230426/cmd/image_editor')
# --- custom ---
from custom_lib import Custom_Lib as custom
# --- common ---
import os
from datetime import datetime
from pathlib import Path
import sys
def main():
print(f'{company_name} {prm_title} v{prm_ver}\n'
f'(c) {company_name}. All rights reserved.\n'
f'System information as of {sys_date}\n')
exit_flag = False
while not exit_flag:
print(f'\n[Exec]\n'
f'[1] {typ1}\n'
f'[2] {typ2}\n'
f'[3] {typ3}\n'
f'[4] {typ4}\n'
f'[5] {typ5}')
try:
input_exec = input('> ')
if input_exec == 'exit':
exit_flag = True
elif input_exec == '1':
while not exit_flag:
print(f'[{typ1}]\nInput HEX or RGB Code\n[9] back')
input_exec1 = input('> ')
if input_exec1 == 'exit':
exit_flag = True
break
elif len(input_exec1) == 6 and input_exec1.count(' ') == 0:
hex2rgb = custom.my_image.hex_to_rgb(input_exec1)
rgb_name = custom.my_image.get_color_name(hex2rgb)
log.info(f'HEX #{input_exec1}')
log.info(f'RGB {hex2rgb[0]} {hex2rgb[1]} {hex2rgb[2]}')
log.info(f'Name {rgb_name}')
elif input_exec1.count(' ') == 2:
rgb_var = tuple(map(int, input_exec1.split()))
rgb2hex = custom.my_image.rgb_to_hex(rgb_var)
hex2rgb = custom.my_image.hex_to_rgb(rgb2hex)
rgb_name = custom.my_image.get_color_name(hex2rgb)
log.info(f'HEX #{rgb2hex}')
log.info(f'RGB {input_exec1}')
log.info(f'Name {rgb_name}')
elif input_exec1 == '9':
break
else:
log.error('Invalid HEX or RGB Code')
elif input_exec == '2':
while not exit_flag:
print(f'[{typ2}]\n[1] Width\n[2] Height\n[9] back')
input_exec2 = input('> ')
if input_exec2 == 'exit':
exit_flag = True
break
elif input_exec2 == '1':
while not exit_flag:
print(f'[{typ2}]\nInput Width\n[9] back')
input_exec2_1 = input('> ')
if input_exec2_1 == 'exit':
exit_flag = True
break
elif input_exec2_1 != '' and input_exec2_1 != 'exit' and input_exec2_1 != '9':
imp_file_list = os.listdir(imp_resize_path)
imp_file_list.remove('raw_data')
if imp_file_list:
for imp_file in imp_file_list:
imp_file_var = os.path.join(imp_resize_path, imp_file).replace('\\', '/')
a = custom.my_image.image_resize(imp_resize_path, imp_resize_raw_path, exp_resize_path, imp_file_var, 'W', int(input_exec2_1))
log.info(a)
break
else:
log.error('Not Found Image')
elif input_exec2_1 == '9':
break
else:
log.error('Invalid Width')
elif input_exec2 == '2':
while not exit_flag:
print(f'[{typ2}]\nInput Height\n[9] back')
input_exec2_2 = input('> ')
if input_exec2_2 == 'exit':
exit_flag = True
break
elif input_exec2_2 != '' and input_exec2_2 != 'exit' and input_exec2_2 != '9':
imp_file_list = os.listdir(imp_resize_path)
imp_file_list.remove('raw_data')
if imp_file_list:
for imp_file in imp_file_list:
imp_file_var = os.path.join(imp_resize_path, imp_file).replace('\\', '/')
a = custom.my_image.image_resize(imp_resize_path, imp_resize_raw_path,
exp_resize_path, imp_file_var, 'H',
int(input_exec2_2))
log.info(a)
break
else:
log.error('Not Found Image')
elif input_exec2_2 == '9':
break
else:
log.error('Invalid Height')
elif input_exec2 == '9':
break
else:
log.error('Invalid Width or Height')
elif input_exec == '3':
while not exit_flag:
imp_file_list = os.listdir(imp_icon_path)
imp_file_list.remove('raw_data')
if imp_file_list:
for imp_file in imp_file_list:
imp_file_var = os.path.join(imp_icon_path, imp_file).replace('\\', '/')
a = custom.my_image.distribute_serveral_png(imp_icon_path, imp_icon_raw_path,
exp_icon_path, imp_file_var)
log.info(a)
# imp_file_var = os.path.join(imp_icon_path, imp_file).replace('\\', '/')
# a = ateciot_image_core.bake_one_big_png_to_ico(imp_icon_path, imp_icon_raw_path,
# exp_icon_path, imp_file_var)
#
# log.info(a)
# a = ateciot_image_core.image_to_icon(imp_icon_path, imp_icon_raw_path,
# exp_icon_path, imp_file_var, int(input_exec3))
#
# log.info(a)
break
elif input_exec == '4':
while not exit_flag:
print(f'[{typ4}]\nInput Extension\n[9] back')
input_exec4 = input('> ')
if input_exec4 == 'exit':
exit_flag = True
break
elif input_exec4 == 'png' or input_exec4 == 'gif' or input_exec4 == 'jpeg' or input_exec4 == 'jpg' or input_exec4 == 'bmp':
imp_file_list = os.listdir(imp_extension_path)
imp_file_list.remove('raw_data')
if imp_file_list:
for imp_file in imp_file_list:
imp_file_var = os.path.join(imp_extension_path, imp_file).replace('\\', '/')
a = custom.my_image.image_to_extension(imp_extension_path, imp_extension_raw_path,
exp_extension_path, imp_file_var, input_exec4)
log.info(a)
break
elif input_exec4 == '9':
break
else:
log.error(f'Option verification failed, please try again.')
elif input_exec == '5':
while not exit_flag:
print(f'[{typ5}]\n[1] Image to Base64\n[2] Base64 to Image\n[9] back')
input_exec5 = input('> ')
if input_exec5 == 'exit':
exit_flag = True
break
elif input_exec5 == '1':
imp_file_list = os.listdir(imp_base64_path)
imp_file_list.remove('raw_data')
if imp_file_list:
for imp_file in imp_file_list:
if '.png' in imp_file or '.gif' in imp_file or '.jpeg' in imp_file or '.jpg' in imp_file or '.bmp' in imp_file:
imp_file_var = os.path.join(imp_base64_path, imp_file).replace('\\', '/')
a, b, c = custom.my_image.image_to_base64(imp_base64_path, imp_base64_raw_path, exp_base64_path, imp_file_var)
with open(f'{c}.txt', "w") as f:
f.write(a)
log.info(b)
else:
log.error('Image to Base64-Not Found Image')
elif input_exec5 == '2':
imp_file_list = os.listdir(imp_base64_path)
imp_file_list.remove('raw_data')
if imp_file_list:
for imp_file in imp_file_list:
if '.txt' in imp_file:
imp_file_var = os.path.join(imp_base64_path, imp_file).replace('\\', '/')
with open(imp_file_var, "r") as f:
line = f.read()
a = custom.my_image.base64_to_image(imp_base64_raw_path, exp_base64_path, line, imp_file_var, f)
log.info(a)
else:
log.error('Base64 to Image-Not Found Text')
elif input_exec5 == '9':
break
else:
log.error(f'Option verification failed, please try again.')
else:
log.error(f'Option verification failed, please try again.')
except Exception as e:
log.error(e)
# --- prm_info_variables ---
company_name = 'ATEC IoT'
prm_title = Path(os.path.basename(sys.argv[0])).stem.replace('_', ' ')
prm_renew_ver = 1
prm_modify_ver = 0
prm_bug_ver = 0
prm_ver = f'{prm_renew_ver}.{prm_modify_ver}.{prm_bug_ver}'
prm_uuid = '6d36fd01-dcc4-11ed-9a10-0456e5df0ac9'
# --- type_variables ---
typ1 = 'Color Info'
typ2 = 'Image Resize'
typ3 = 'Image to Icon'
typ4 = 'Image Extension'
typ5 = 'Base64'
# --- path_variables ---
loc_path = os.getcwd()
imp_path = f"{loc_path}/import/"
imp_resize_path = f"{imp_path}resize/"
imp_resize_raw_path = f"{imp_resize_path}raw_data/"
imp_icon_path = f"{imp_path}icon/"
imp_icon_raw_path = f"{imp_icon_path}raw_data/"
imp_extension_path = f"{imp_path}extension/"
imp_extension_raw_path = f"{imp_extension_path}raw_data/"
imp_base64_path = f"{imp_path}base64/"
imp_base64_raw_path = f"{imp_base64_path}raw_data/"
exp_path = f"{loc_path}/export/"
exp_resize_path = f"{exp_path}resize/"
exp_resize_raw_path = f"{exp_resize_path}raw_data/"
exp_icon_path = f"{exp_path}icon/"
exp_extension_path = f"{exp_path}extension/"
exp_base64_path = f"{exp_path}base64/"
path_list = [imp_path,
imp_resize_path,
imp_resize_raw_path,
imp_icon_path,
imp_icon_raw_path,
imp_extension_path,
imp_extension_raw_path,
imp_base64_path,
imp_base64_raw_path,
exp_path,
exp_resize_path,
exp_resize_raw_path,
exp_icon_path,
exp_extension_path,
exp_base64_path]
# --- common_variables ---
datetime = datetime.now()
sys_date = datetime.strftime('%Y.%m.%d %H:%M:%S')
''' build command'''
# pyinstaller --specpath=.\20230426\app\spec\ --distpath=.\20230426\app\dist\ --workpath=.\20230426\app\build\ --name=Image_Editor -c -D C:\Users\Administrator\PycharmProjects\pythonProject\20230426\cmd\image_editor\Image_Editor.py --hidden-import=webcolors --hidden-import=PIL --hidden-import=cv2 --hidden-import=numpy --hidden-import=uuid --hidden-import=logging --paths="C:\Users\Administrator\PycharmProjects\pythonProject\venv\lib\site-packages\cv2\cv2.cp39-win_amd64.pyd"
# pyinstaller --distpath=.\ESL\app\dist\ --workpath=.\ESL\app\bulid\ -F C:\Users\ATECAP\PycharmProjects\pythonProject\ESL\app\spec\Weather_Crawling.spec
if __name__ == '__main__':
custom.init()
if prm_uuid != None:
log = custom.my_logger.logger()
try:
for file_path in path_list:
if not os.path.isdir(file_path):
os.makedirs(file_path)
main()
except Exception as e:
log.error(e)