コード例 #1
0
def composeIconWithBadge(floatIcon_Path,appIcon_path):

    # 获取icon原图
    origin_image = Image.open(appIcon_path).convert("RGBA")

    # 获取角标
    float_icon = Image.open(floatIcon_Path)

    # 处理角标问题
    if origin_image.size[0] != origin_image.size[1]:
        print('FloatIcon file must be a rectangle!')
        return

    # 获取图片宽高
    origin_imageW = origin_image.size[0]

    # 角标大小跟icon保持一致
    float_icon = float_icon.resize((origin_imageW, origin_imageW), Image.BILINEAR)

    # #粘贴角标到icon
    # origin_image.paste(float_icon,(0,0,origin_imageW,origin_imageW))

    iconImage = Image.alpha_composite(origin_image, float_icon)  # 能看到 float_icon 的黑色背景

    # file_manager.joinFilePath(file_manager.getFullPath(Index.temp_badge))
    temp_badge_path = file_manager.createFilePath(file_manager.getFullPath(Index.temp_badge))
    iconImage.save(temp_badge_path + "/badge_icon.png" , "png")
    print(temp_badge_path + "/badge_icon.png")

    print("已经处理完角标----------")
コード例 #2
0
ファイル: icon_tool.py プロジェクト: yongtaovip/AppIconMaker
def processingIcons(appicon_path="", platform="ios", sizeArray=[]):
    """APPIcon的处理流程"""
    # 获取icon原图
    origin_image = Image.open(appicon_path).convert("RGBA")

    for x in range(0, len(sizeArray)):
        width = sizeArray[x][1]
        # 调整图像大小
        outImage = origin_image.resize((width, width), Image.BILINEAR)

        if platform == "ios":
            imgName = sizeArray[x][0] + ".png"
            file_manager.joinFilePath(
                file_manager.getFullPath(Index.temp_icon),
                platform + "/AppIcon.appiconset")
            temp_ios_path = file_manager.createFilePath(
                file_manager.getFullPath(Index.temp_icon) + platform +
                "/AppIcon.appiconset")
            print(temp_ios_path)
            outImage.save(temp_ios_path + "/" + imgName, "png")
            print(temp_ios_path + "/" + imgName)
            if x == 0:
                file_manager.joinFilePath(
                    file_manager.getFullPath(Index.temp_icon), platform)
                temp_ios_path = file_manager.createFilePath(
                    file_manager.getFullPath(Index.temp_icon) + platform +
                    "/AppIcon.appiconset")
                content_path = file_manager.getFullPath("upload/icon/jsonfile")
                log_utils.info(temp_ios_path + "\n" + content_path)
                file_manager.copyFiles(content_path, temp_ios_path)

        elif platform == "android":
            typeFileName = sizeArray[x][0]
            imgName = "ic_launcher.png"
            file_manager.joinFilePath(
                file_manager.getFullPath(Index.temp_icon),
                platform + "/" + typeFileName)
            temp_android_path = file_manager.createFilePath(
                file_manager.getFullPath(Index.temp_icon) + platform + "/" +
                typeFileName)
            print(temp_android_path)
            outImage.save(temp_android_path + "/" + imgName, "png")
            print(temp_android_path + "/" + imgName)
        else:
            log_utils.warning("平台选择错误")
コード例 #3
0
ファイル: Index.py プロジェクト: yongtaovip/AppIconMaker
def checkResourcesDir():
    log_utils.info("正在检查资源路径,请稍后.....")
    # 检查备用资源
    dirs = [
        root_icon, root_splash, root_badge, output_icon, output_splash,
        output_badge
    ]
    for item in dirs:
        log_utils.info(file_manager.createFilePath(item))
コード例 #4
0
def make_archiveWithInfo():
    """压缩文件到指定文件夹"""
    nowtimestr = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
    temp_splash_path = file_manager.createFilePath(
        file_manager.getFullPath(Index.temp_splash))
    new_path = shutil.make_archive(
        file_manager.getFullPath(Index.output_splash) + nowtimestr, 'zip',
        temp_splash_path)
    log_utils.printf()
    log_utils.info("打包结束之后的zip路径为:" + new_path)
コード例 #5
0
def processingWithSplash(image_path, platform="ios", ImageList=[]):
    # 加载图形
    origin_image = Image.open(image_path)
    w = float(origin_image.size[0])
    h = float(origin_image.size[1])
    # 先处理图片,然后根据需求进行图片的裁剪
    for i in range(0, len(ImageList)):

        if i == 0:
            file_manager.joinFilePath(
                file_manager.getFullPath(Index.temp_splash), platform)
            temp_splash_path = file_manager.createFilePath(
                file_manager.getFullPath(Index.temp_splash) + platform +
                "/LaunchImage.launchimage/")
            content_path = file_manager.getFullPath("upload/splash/jsonfile")
            file_manager.copyFiles(content_path, temp_splash_path)

        (dest_w, dest_h) = ImageList[i][1]
        if w > h:
            print("------------------检测到是横屏的图片,进行处理--------------------------")
            # 宽大于高,说明是横屏闪屏,切图以高为基准
            if dest_w > dest_h:
                print(origin_image.size)
                print((dest_w, dest_h))
                # 压缩图片(计算宽高)
                resizeH = dest_h
                resizeW = int(float(dest_h / h) * w)
                # 原始坐标为0 ,计算放大后的图像 左右的间距
                originx = 0
                if resizeW > dest_w:
                    originx = (resizeW - dest_w) / 2
                else:
                    originx = (dest_w - resizeW) / 2
                # 原图根据目标图进行缩放,传入的比较大分辨率,缩小
                origin_image = origin_image.resize((resizeW, resizeH),
                                                   Image.ANTIALIAS)
                # 创建一张白色背景
                bgimageview = Image.new('RGBA', (dest_w, dest_h),
                                        (255, 255, 255))
                # 粘贴压缩之后的图到背景上准备裁剪
                bgimageview.paste(origin_image, (int(-originx), 0))
                # 保存到临时目录文件中
                file_manager.joinFilePath(
                    file_manager.getFullPath(Index.temp_splash), platform)
                bgimageview.save(
                    file_manager.createFilePath(
                        file_manager.getFullPath(Index.temp_splash) +
                        platform + "/LaunchImage.launchimage/") +
                    ImageList[i][0] + ".png", "png")
                print(
                    file_manager.getFullPath(Index.temp_splash) + platform +
                    "/LaunchImage.launchimage/" + ImageList[i][0] + ".png")
        else:

            # 宽小于高,说明是竖屏闪屏,切图以宽为基准
            print("------------------检测到是竖屏的图片,进行处理--------------------------")
            if dest_w < dest_h:
                # 压缩图片(计算宽高)
                resizeH = int(float(dest_w / w) * h)
                resizeW = dest_w
                if resizeH > dest_h:
                    originy = (resizeH - dest_h) / 2
                else:
                    originy = (dest_h - resizeH) / 2
                # 原图根据目标图进行缩放,传入的比较大分辨率,缩小
                origin_image = origin_image.resize((resizeW, resizeH),
                                                   Image.ANTIALIAS)
                # 创建一张白色背景
                bgimageview = Image.new('RGBA', (dest_w, dest_h),
                                        (255, 255, 255))
                # 粘贴压缩之后的图到背景上准备裁剪
                bgimageview.paste(origin_image, (0, int(-originy)))

                # 保存到临时目录文件中
                file_manager.joinFilePath(
                    file_manager.getFullPath(Index.temp_splash), platform)
                bgimageview.save(
                    file_manager.createFilePath(
                        file_manager.getFullPath(Index.temp_splash) +
                        platform + "/LaunchImage.launchimage/") +
                    ImageList[i][0] + ".png", "png")
                print(
                    file_manager.getFullPath(Index.temp_splash) + platform +
                    "/LaunchImage.launchimage/" + ImageList[i][0] + ".png")
コード例 #6
0
def processingAndroidSplash(image_path, platform="android", ImageList=[]):
    # 加载图形
    origin_image = Image.open(image_path)

    w = float(origin_image.size[0])
    h = float(origin_image.size[1])
    # 先处理图片,然后根据需求进行图片的裁剪
    for i in range(0, len(ImageList)):

        (dest_w, dest_h) = ImageList[i][1]
        splashfilename = ImageList[i][0]

        if w > h:
            print("------------------检测到是横屏的图片,进行处理--------------------------")
            # 宽大于高,说明是横屏闪屏,切图以高为基准
            if dest_w > dest_h:
                print(origin_image.size)
                print((dest_w, dest_h))

                # 压缩图片(计算宽高)
                resizeH = dest_h
                resizeW = int(float(dest_h / h) * w)

                # 原始坐标为0 ,计算放大后的图像 左右的间距
                originx = 0
                if resizeW > dest_w:
                    originx = (resizeW - dest_w) / 2
                else:
                    originx = (dest_w - resizeW) / 2

                # 原图根据目标图进行缩放,传入的比较大分辨率,缩小
                origin_image = origin_image.resize((resizeW, resizeH),
                                                   Image.ANTIALIAS)

                # 创建一张白色背景
                bgimageview = Image.new('RGBA', (dest_w, dest_h),
                                        (255, 255, 255))
                # 粘贴压缩之后的图到背景上准备裁剪
                bgimageview.paste(origin_image, (int(-originx), 0))

                # 保存到临时目录文件中
                file_manager.joinFilePath(
                    file_manager.getFullPath(Index.temp_splash), platform)
                bgimageview.save(
                    file_manager.createFilePath(
                        file_manager.getFullPath(Index.temp_splash) +
                        platform + "/" + splashfilename) + "/splash.png",
                    "png")
                log_utils.info("保存Splash" +
                               file_manager.getFullPath(Index.temp_splash) +
                               platform + "/" + splashfilename + "splash.png")

        else:

            # 宽小于高,说明是竖屏闪屏,切图以宽为基准
            print("------------------检测到是竖屏的图片,进行处理--------------------------")

            if dest_w < dest_h:

                # 压缩图片(计算宽高)
                resizeH = int(float(dest_w / w) * h)
                resizeW = dest_w

                originy = 0
                if resizeH > dest_h:
                    originy = (resizeH - dest_h) / 2
                else:
                    originy = (dest_h - resizeH) / 2

                # 原图根据目标图进行缩放,传入的比较大分辨率,缩小
                origin_image = origin_image.resize((resizeW, resizeH),
                                                   Image.ANTIALIAS)

                # 创建一张白色背景
                bgimageview = Image.new('RGBA', (dest_w, dest_h),
                                        (255, 255, 255))
                # 粘贴压缩之后的图到背景上准备裁剪
                bgimageview.paste(origin_image, (0, int(-originy)))

                # 保存到临时目录文件中
                file_manager.joinFilePath(
                    file_manager.getFullPath(Index.temp_splash), platform)
                bgimageview.save(
                    file_manager.createFilePath(
                        file_manager.getFullPath(Index.temp_splash) +
                        platform + "/" + splashfilename) + "/splash.png",
                    "png")
                print("保存Splash" +
                      file_manager.getFullPath(Index.temp_splash) + platform +
                      "/" + splashfilename + "splash.png")