Пример #1
0
        def prodbilder(prodkat, pn):
            er = False
            try:

                for filename in find_files(
                                        home + r"/[email protected]/Produktbilder/Shopscreenshots nicht editiert/" + prodkat,
                                        '*.' + pn):
                    pname = filename.replace(
                        home + r"/[email protected]/Produktbilder/Shopscreenshots nicht editiert/" + prodkat, "")
                    gname = os.path.abspath(filename)
                    try:
                        resize3(gname)
                        try:
                            source = tinify.from_file(gname)
                            source.to_file(gname)
                        except Exception as e:
                            f = open(home + r"/[email protected]/Produktbilder/fehler/error.log", 'a')
                            for g in e.args:
                                print("\a")
                                f.write(g)
                                f.write(pname + ": " + "\n")
                            f.close()
                        print(pname)
                    except Exception as e:
                        er = True
                        print("Error: " + pname)
                        print(e)
            except Exception as e:
                er = True
                print(e)
            return er
Пример #2
0
 def resize(options, width, height, src_file_fp, dst_file_fp):
     """
     调整大小也算是一种压缩
     """
     assert options in ['scale', 'fit', 'cover', 'thumb']
     source = tinify.from_file(src_file_fp)
     resized = source.resize(
         method=options,
         width=width,
         height=height
     )
     ret = resized.to_file(dst_file_fp)
     return ret
Пример #3
0
def Tinicompopt(f):
    tinify.key = "KHdQmr04kWs6b4tfpm5bYgQHVzVTBS3v"
    for x in range(0, len(f)):

        result = f[x].filename[::-1].find('/')
        typ = f[x].filename[-3:]
        typ = typ.lower()
        print(typ)
        o = f[x].filename[-result - 1:-4] + "." + typ

        source = tinify.from_file(path=f[x])
        source.to_file(o)
        return o
Пример #4
0
def Tiniresopt(f, h, w):
    tinify.key = "KHdQmr04kWs6b4tfpm5bYgQHVzVTBS3v"
    h = int(h)
    w = int(w)
    for x in range(0, len(f)):

        result = f[x].filename[::-1].find('/')
        typ = f[x].filename[-3:]
        typ = typ.lower()
        print(typ)
        o = f[x].filename[-result - 1:-4] + "." + typ

        source = tinify.from_file(path=f[x])
        if (h != 0 and w != 0):
            resized = source.resize(method="fit", width=w, height=h)

        else:
            resized = source.resize(method="fit", width=150, height=100)
        resized.to_file(o)
        return o
Пример #5
0
    def run(self):
        date = time.strftime('%H:%M - %d.%m.%y')
        path_to_watch = home + "/Google Drive/TinyPng/Resize It/"
        path_to_write = home + "/Google Drive/TinyPng/Resized/"
        before = dict([(f, None) for f in os.listdir(path_to_watch)])
        while 1:
            edited = get_edit("Resi.json")
            after = dict([(f, None) for f in os.listdir(path_to_watch)])
            added = [f for f in after if not f in before]
            removed = [f for f in before if not f in after]
            # if added:
            for i in after:
                ending = os.path.splitext(i)[1]
                if ending == ".jpg" or ending == ".png" or ending == ".jpeg" or ending == ".gif" or ending == ".PNG":
                    path = path_to_watch + i
                    gname = os.path.abspath(path)
                    v = os.path.splitext(i)[0]
                    if gname not in edited:
                        try:
                            source = tinify.from_file(path)
                            source.to_file(path_to_write + v + ".png")
                        except:
                            tinify.key = gg.remove(tinify.key)
                            tinify.key = gg[0]
                            with open(crnt + r"/gg.json", "w") as file:
                                json.dump(gg, file)

                        resize(path_to_write + v + ".png")
                        edited.append(gname)
                    os.remove(path)
            if added:
                print("Added: ", ", ".join(added))

            if removed: print("Removed: ", ", ".join(removed))
            before = after
            sav_edit("Resi.json", edited)
Пример #6
0
 def core_from_tinify(src_file_fp, dst_file_fp):
     print(f'-from--{src_file_fp}--------to-----{dst_file_fp}-------')
     ret = tinify.from_file(src_file_fp).to_file(dst_file_fp)
     return ret
Пример #7
0
images_folder = config['images_folder']
tinify_key = config["tinify_key"]

if tinify_key is None or tinify_key is '' or tinify_key == '-':
    print("No tinify key given")
else:
    tinify.key = tinify_key
    files = get_files(images_folder)

    files.sort(key=lambda s: -s[0])

    try:
        for pair in files:
            print("tinifying file: {} - size before: {} - size after: ".format(
                pair[1], pair[0]),
                  end='')

            try:
                source = tinify.from_file(pair[1])
                source.to_file(pair[1])
                print(os.path.getsize(pair[1]))
            except ClientError as er:
                print("Client Error while tinifying: {}".format(er))
            except ServerError as er:
                print("Server Error while tinifying: {}".format(er))
            except ConnectionError as er:
                print("Connection Error while tinifying: {}".format(er))

    except tinify.AccountError as e:
        print("Account Error while tinifying: {}".format(e))