def convert_freemarker_path(fm_path):
    """
    把指定目录下的模版文件中的Freemark语法,同一替换成Jinjia2语法
    :param fm_path: 指定目录
    :return:无
    """
    path_list = filecm.search_files(fm_path, ".tpl,.json,.ftl")
    for tpl_path in path_list:
        fm_str = filecm.read_str(file_name=tpl_path)
        jj_str = freemarker_to_jinjia2(fm_str)
        diffcm.diff_by_text(fm_str, jj_str)
        filecm.save_str(jj_str, file_name=tpl_path)
Exemple #2
0
def scale_img_folder(folder_path, scale_width, scale_height, ext=".png,.jpg,jpeg", match=None):
    """
    缩放指定图片文件目录下所有图片到指定大小并覆盖原图
    @:param folder_path 指定图片目录
    @:param scale_width 宽度
    @:param scale_height 高度
    @return: 无
    """

    # 对图片目录遍历
    path_list = filecm.search_files(folder_path, ext=ext, match=match)
    # 对所有文件进行缩放
    for file_path in path_list:
        scale_img_file(file_path, scale_width, scale_height)
Exemple #3
0
 def make_by_path(self, path, path_map, cfg_obj):
     """
     按照指定模版目录,和路径Map,进行代码生成
     :param path: 模版目录
     :param path_map: 路径Map
     :param cfg_obj: 配置数据
     :return: 文件生成数
     """
     make_count = 0
     path = os.path.join(self.tpl_path, path)
     tpl_list = filecm.search_files(path, ".tpl")
     for tpl_path in tpl_list:
         out_file_tpl = path_map[filecm.short_name(tpl_path)]
         self.make_by_tpl(tpl_path, out_file_tpl, cfg_obj)
         make_count += 1
     return make_count
Exemple #4
0
    def LoadTexture(self):
        # 提前准备好的6个图片
        # imgFiles = [str(i) + '.jpg' for i in range(1, 7)]
        # 取得图片列表
        imgFiles = filecm.search_files(cfg["img_root"], cfg['img_ext'],
                                       r'^[^\.]+')

        for i in range(6):
            img = Image.open(imgFiles[i])
            width, height = img.size
            img = img.tobytes('raw', 'RGBX', 0, -1)

            # 根据纹理参数返回n个纹理索引。
            glGenTextures(2)
            glBindTexture(GL_TEXTURE_2D, i)
            glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0, GL_RGBA,
                         GL_UNSIGNED_BYTE, img)
            glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP)
            glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP)
            glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
            glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
            glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
            glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL)
Exemple #5
0
default_config = """
{
    "img_root": "./images/faces/",
    "max_count" : 10,
    "fps": 1,
    "save_path": "./temp/output.pptx",
    "width": 1024,
    "height": 683
}
"""

# 加载配置文件
cfg = loadcfgcm.load("file_pptx_from_img.json", default_config)

pptFile = pptx.Presentation()

# 取得图片列表
path_list = filecm.search_files(cfg["img_root"], '.jpeg', r'^[^\.]+')

# 按图片编号顺序导入
for fn in path_list:
    slide = pptFile.slides.add_slide(pptFile.slide_layouts[1])

    # 为PPTX文件当前幻灯片中第一个文本框设置文字,本文代码中可忽略
    slide.shapes.placeholders[0].text = fn[:fn.rindex('.')]

    # 导入并为当前幻灯片添加图片,起始位置和尺寸可修改
    slide.shapes.add_picture(fn, Inches(0), Inches(0), Inches(10), Inches(7.5))

pptFile.save('./temp/img_to_pptx.pptx')
Exemple #6
0
     "action" : "copy|move",
    "src_path": "",
    "target_path": "",
    "target_w": 1280,
    "target_h": 800,
    "src_ext": "png",
    "target_ext": "jpg"
}
"""

# 加载配置文件
cfg = loadcfgcm.load("file_img_convert.json", default_config)

# 检索图片列表
search_path = ''
path_list = filecm.search_files(cfg["src_path"], '.' + cfg["src_ext"],
                                r'^[^\.]+')
logcm.print_obj(path_list, 'path_list')

# 横版图片路径列表
w_list = []
h_list = []
count = 1
for path in path_list:
    # 调整图片尺寸并保存
    (file_path, file_name) = os.path.split(path)
    (short_name, extension) = os.path.splitext(file_name)
    # 修改大小
    im_new = imagecm.resize(path,
                            cfg["target_w"],
                            cfg["target_h"],
                            keep_ratio=True)
Exemple #7
0
        "title_line": 0,
        "col_titles": ["基金名称", "投资者名称", "客户类型", "证件类型", "证件号码", "????"]
    }],
    "YYYYYY": [{
        "sheet_name": "客户明细J",
        "title_line": 0,
        "col_titles": ["????", "客户名称", "客户类型", "证件类型", "证件号码", "持有份额"]
    }]
}
"""

# 加载配置文件
config_map = loadcfgcm.load("file_load_xls.json", default_config)

# 取得指定目录下的文件列表
path_list = filecm.search_files(root_dir, '.xlsx,.xls', r'^[^~]+')
logcm.print_obj(path_list, "path_list")

# 读取文件数
read_file_cnt = 0
# 读取数据行数
read_line_cnt = 0

# 路径列表
for path in path_list:
    # 短文件名
    short_name = filecm.short_name(path)
    # 根据文件名取得配置列表
    if short_name not in config_map:
        print("==========未找到配置:%s" % short_name)
        continue
Exemple #8
0
{
    "remark" : "图片按照横竖分类复制或移动",
     "action" : "copy|move",
    "src_path": "",
    "target_path_w": "",
    "target_path_h": "",
    "skeep_exist": true
}
"""

# 加载配置文件
cfg = loadcfgcm.load("file_img_movecopy.json", default_config)

# 检索图片列表
search_path = ''
path_list = filecm.search_files(cfg["src_path"], '.jpg', r'^[^\.]+')
logcm.print_obj(path_list, 'path_list')

# 横版图片路径列表
w_list = []
h_list = []
for path in path_list:
    if imagecm.is_landscape(path):
        w_list.append(path)
    else:
        h_list.append(path)
logcm.print_obj(w_list, 'w_list')
logcm.print_obj(h_list, 'h_list')

# 复制图片
if cfg['action'] == "copy":
# 加载配置文件
cfg = loadcfgcm.load("cv_video_from_img.json", default_config)

# 创建目录
filecm.makedir(cfg['save_path'], True)
filecm.makedir('./temp/cv/video-from-img')

# 新建视频写入类
fourcc = cv2.VideoWriter_fourcc(*"MJPG")
videoWriter = cv2.VideoWriter(cfg['save_path'], fourcc, cfg['fps'],
                              (cfg['width'], cfg['height']))
im_output = VideoImageOutput(videoWriter)

# 取得图片列表
path_list = filecm.search_files(cfg["img_root"], cfg['img_ext'], r'^[^\.]+')
# 取得处理数量
max_size = cfg['max_count']
if max_size > len(path_list):
    max_size = len(path_list)

# 减速列表
slow_move_h = imagecm.slow_down(-1 * cfg['width'], 0, 10)
slow_move_v = imagecm.slow_down(-1 * cfg['height'], 0, 10)
# 加速列表
speed_move_h = imagecm.speed_up(0, cfg['width'], 10)
speed_move_v = imagecm.speed_up(0, cfg['height'], 10)
# 压缩
speed_zip = imagecm.speed_up(0.01, 1.0, 10)
slow_zip = imagecm.slow_down(1.0, 0.01, 10)
# 放大
"""

from common import filecm
from common import imagecm
from common import logcm

# 读取图片尺寸
img_path = './images/draw_box_result.jpg'
size = imagecm.get_size(img_path)
logcm.print_obj(size, 'size')

# 调整图片尺寸并保存
save_path = './temp/draw_box_result_thumb.jpg'
imagecm.resize(img_path, 500, 500, save_path, keep_ratio=True)

# 检索图片列表
search_path = '/Volumes/Transcend/data/down/aaa/photo/makeH'
path_list = filecm.search_files(search_path, '.jpg', r'^[^\.]+')
logcm.print_obj(path_list, 'path_list')

# 横版图片路径列表
copy_list = []
for path in path_list:
    if imagecm.is_landscape(path):
        copy_list.append(path)
logcm.print_obj(copy_list, 'copy_list')

# 复制图片
copy_path = '/Volumes/Transcend/data/down/aaa/photo/makeW'
filecm.move_files(copy_list, copy_path)