def create_png8(folder_name, is_gold=False): with open(CONFIG) as f: config = yaml.load(f) root = config.get('working_dir') if is_gold: src_dir = config.get('output_png24_gold_dir') else: src_dir = config.get('output_png24_dir') dst_dir = os.path.join(root, folder_name) os.makedirs(dst_dir, exist_ok=True) cards_data = get_cards_data(config, local=True) for card_data in cards_data: key = card_data.get('key') card_src = os.path.join(src_dir, "{}.png".format(key)) card_dst = os.path.join(dst_dir, "{}.png".format(key)) try: pngquant.quant_image(image=card_src, dst=card_dst) logger.info(card_dst) except IOError: logger.error(f"Cannot create thumbnail for {key}")
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)
if Check_Process == "Y" or Check_Process == "y": #Process audio files Music_Process = AudioSegment.from_file( r"" + Download_Addrass + "/" + str(Music_ID).rjust(3, '0') + '.' + music.type, music.type) one_minute = 60 * 1000 Music_Save = Music_Process[:one_minute] Music_Save.export(r"" + Download_Addrass + "/" + str(Music_ID).rjust(3, '0') + ".mp3", format="mp3") if music.type != "mp3": os.remove( os.path.join( Download_Addrass, str(Music_ID).rjust(3, '0') + '.' + music.type)) pngquant.quant_image(Img_Name) while getsize(Img_Name) > 1000000: Img_Re = Image.open(Img_Name) Img_Re = Img_Re.resize( (int(Img_Re.size[0] / 2), int(Img_Re.size[1] / 2))) Img_Re.save(Img_Name) print("NO." + str(Music_ID).rjust(3, '0') + " processing completed!") Txt_File = open(r"" + Download_Addrass + "/" + str(Music_ID).rjust(3, '0') + ".txt", mode='w', encoding="utf-8") Txt_File.write("Music Name: " + music.name + "\n\n" + "Artist Name: ") for artist in music.artist: Txt_File.write(artist + " ")
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抖动 '''