Exemplo n.º 1
0
 def __init__(self, driver):
     # chrome_options = Options()
     # chrome_options.add_argument("--headless")
     # chrome_options.add_argument("--proxy-server=socks5://127.0.0.1:1080")
     # self.driver = webdriver.Chrome(options=chrome_options)
     self.driver = driver
     self.afterHeadlessInstance = int(round(time.time() * 1000))
     self.beforeOpenPage = 0
     self.afterOpenPage = 0
     pngquant.config(min_quality=70, max_quality=95, speed=1)
Exemplo n.º 2
0
Arquivo: pack.py Projeto: vmjcv/sunset
 def change_resfile_byquant(self, ):
     #压缩图片深度为8位
     #if self.m_system=="Windows":
     #   pass
     #elif self.m_system=="Darwin":
     #   pass
     filePathVector = getFilesAbsolutelyPath(self.m_outputfile)
     for filename in filePathVector:
         flag = filename.find(".png")
         if flag != -1:
             pngquant.config("./pngquant.exe",
                             min_quality=80,
                             max_quality=100)
             pngquant.quant_image(filename)
Exemplo n.º 3
0
def main(argv):
    try:
        opts, args = getopt.getopt(argv, 'hf:d:', ['help', 'file=', 'dir='])
    except getopt.GetoptError:
        # usage()
        sys.exit(2)
    for opt, arg in opts:
        if opt in ('-h', '--help'):
            # usage()
            sys.exit()
        elif opt in ('-f', 'file'):
            quant_file = arg
        elif opt in ('-d', '--dir'):
            quant_dir = arg

    pngquant.config(quant_file)
    pngquant.quant_dir(quant_dir)
Exemplo n.º 4
0
    def optimize_images(self):
        # PNGQUANT
        # def config(self, quant_file=None, min_quality=None, max_quality=None, ndeep=None, ndigits=None, tmp_file=None):
        # def quant_data(self, data=None, dst=None, ndeep=None, ndigits=None, delete=True):
        # def quant_image(self, image=None, dst=None, ndeep=None, ndigits=None, override=True, delete=True):
        # def quant_dir(self, dir=None, dst=None, ndeep=None, ndigits=None, override=True, delete=True, topdown=True):
        def optimize(origin, destination):
            print(origin)
            # tiny = tinify.from_file(origin)
            # tiny.to_file(opt)
            return

        for bitmap in self.bitmaps:
            bitmap_name = bitmap[0]
            bitmap_data = bitmap[1]

            if bitmap_name.endswith('.png'):
                before = len(bitmap_data)
                pngquant.config(min_quality=40, max_quality=95)
                bitmap[1] = pngquant.quant_data(bitmap_data)[1]
                after = len(bitmap[1])
                print('PNG optimized by {0:.1f}%'.format(100 - (
                    (after / before) * 100)))
Exemplo n.º 5
0
# -*- coding: utf-8 -*-

import pngquant
import qiniu
from django.conf import settings


QINIU = settings.QINIU
auth = qiniu.Auth(QINIU['access_key'], QINIU['secret_key'])
pngquant.config(settings.PNG_QUANT_FILE)


def upload(data, compress=True, key=None, mime_type='application/octet-stream', bucket=QINIU['bucket']):
    data = pngquant.quant_data(data)[1] if compress else data
    token = auth.upload_token(bucket, key=key)
    ret, _ = qiniu.put_data(token, key, data, mime_type=mime_type)
    return ret


def upload_with_file(f, bucket=QINIU['bucket']):
    ret = upload(f['body'], mime_type=f['content_type'], bucket=bucket)
    return ret and ret.get('key')


def qiniu_file_url(key):
    return key and (u'{}{}'.format(QINIU['domain'], key) if not key.startswith('http') else key)


def qiniu_file_url_https(key):
    return key and (u'{}{}'.format(QINIU['domain_https'], key) if not key.startswith('http') else key.replace(QINIU['domain'], QINIU['domain_https']))
Exemplo n.º 6
0
import os
import shutil
import sys

import pngquant
import requests
import yaml
from PIL import Image
from PIL import ImageCms

logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)

CONFIG = os.path.join("config.yaml")

pngquant.config('/usr/local/bin/pngquant')


def load_json(filename):
    """Load json by filename."""
    with open(filename, encoding='utf-8', mode='r') as f:
        data = json.load(f)
    return data


def get_cards_data(config, local=False):
    if local:
        cards_data = load_json(config["cards_data"])
    else:
        r = requests.get(config["cards_data_url"])
        cards_data = r.json()
Exemplo n.º 7
0
import pngquant

pngquant.config(r'D:\pngquant\pngquant.exe')
image = pngquant.quant_image('chiji.png', dst='666_2.png', ndeep=2)



'''
--force --speed=1 --quality=50-90
--force 强制覆盖现有的输出文件(短选项:-f)
--skip-if-larger 在压缩时仅保存小于原始的文件
--output file    输出文件目标文件路径,而不是--ext (短命令: -o)
--ext 设置输出文件名的自定义后缀/扩展名
--quality 设置图片颜色范围,值为0-100
--speed   设置速度和图片质量,速度越快质量越差。参数:1=slow, 3=default, 11=fast & rough
--nofs    禁止Floyd-Steinberg抖动
'''

Exemplo n.º 8
0
# -*- coding: utf-8 -*-

import pngquant
import qiniu
from django.conf import settings

QINIU = settings.QINIU
auth = qiniu.Auth(QINIU['access_key'], QINIU['secret_key'])
pngquant.config(settings.PNG_QUANT_FILE)


def upload(data,
           compress=True,
           key=None,
           mime_type='application/octet-stream',
           bucket=QINIU['bucket']):
    data = pngquant.quant_data(data)[1] if compress else data
    token = auth.upload_token(bucket, key=key)
    ret, _ = qiniu.put_data(token, key, data, mime_type=mime_type)
    return ret


def upload_with_file(f, bucket=QINIU['bucket']):
    ret = upload(f['body'], mime_type=f['content_type'], bucket=bucket)
    return ret and ret.get('key')


def qiniu_file_url(key):
    return key and (u'{}{}'.format(QINIU['domain'], key)
                    if not key.startswith('http') else key)