Python Batch png turn ico

One 、 Preface :

First of all ico Role of documents :ico yes windows The icon file format of , It can be used to display the first icon in the browser , It can also be used for Windows Software . My words are usually used to beautify Folder icon . Like this :

Two 、 Ideas :

  1. ico Standards of documentation :

    ico The document must be square .

    You can do an experiment : Find a square file on the Internet , The suffix to ico It can also be successful .

    Common sizes :256*256

  2. png Icon download site :Iconfont- Alibaba vector icon library

  3. Can handle pictures Python library :pillow

    Installation method :pip install pillow

3、 ... and 、 Code :

import os
# PIL : Python Imaging Library
from PIL import Image # Get the file name in the directory
files = os.listdir()
# Icon size
size = (256,256) # Create a separate one for the icon file icon Catalog
if not os.path.exists('icon'):
os.mkdir('icon') for inName in files:
# Separating file names from extensions
tmp = os.path.splitext(inName)
# because python The files are in the same directory as the pictures , So we need to judge
if tmp[1] == '.png':
outName = tmp[0] + '.ico'
# Open the picture and set the size
im = Image.open(inName).resize(size)
try:
# Save the icon file to icon Catalog
path = os.path.join('icon', outName)
im.save(path) print('{} --> {}'.format(inName, outName))
except IOError:
print('connot convert :',inName)

Execution results :

Four 、 Information :

  1. ICO(Windows The icon file format of )_ Baidu Encyclopedia (baidu.com)

  2. Python Batch conversion png Picture is ico_ The cat in North Lane -CSDN Blog

Python Batch png turn ico More articles about

  1. python Batch file modification operation

    python Batch modify file extension Downloaded some files on the Internet , For some reason , The extension has one more suffix '.xxx', If you modify it manually, because there are too many files , It takes time and effort to reform , So decided to write a small script to modify . 1. The main points of : import r ...

  2. Python Batch modify the content of the text file

    Python Batch replacement of file contents , Supports nested folders import os path="./" for root,dirs,files in os.walk(path): for name ...

  3. python Bulk changes linux Host password

    +++++++++++++++++++++++++++++++++++++++++++ title :python Bulk changes Linux Server password time :2019 year 2 month 24 Daily content : be based on python Realize batch modification linu ...

  4. use python Batch to database (MySQL) Import data from

    use python Batch to database (MySQL) Import data from There are hundreds of thousands of data , The following scrambled data is imported The data format of the table inside the database is as follows, which is the same as the table structure below Current database: pyt ...

  5. python Batch configure security groups for virtual machines

    python Batch configure security groups for virtual machines Use the idea of public cloud to think, to achieve a safe and stable . Scalable and economical business architecture , Cloud operation and maintenance is different from traditional operation and maintenance , For example, everyone who knows about the public cloud knows the concept of security group , Security groups are very similar to firewalls , Then my machine ...

  6. use Python Bulk download DACC Of MODIS data

    I try to use for the first time Python Bulk download DACC Of MODIS data , Write down the steps , Remind yourself of , The data is still being downloaded , Success is unknown , Waiting for the results ...... If there is something wrong with the procedure , Hope to point out , Thank you for . 1. download Python ...

  7. Python Batch modify image format and size

    Python Batch modify image format and size remarks : 1. Imported PIL library , It's for pictures , Very powerful ; 2. Imported win32 library , It is used to judge hidden files , Our project needs to remove hidden files , If you don't need it, you can find it and delete it . 3. Import ...

  8. tinypng Of python Batch compression picture function

    tinypng The image compression function provided by the website is very good , But there are limits to compressing directly on the website , It's troublesome to compress a lot of pictures , Fortunately, the official provides a lot of script automatic compression interface . Let's talk about it briefly python Batch compression steps . 1. apply api key ...

  9. Python Batch copy and rename files

    Python Batch copy and rename files Sample code #! /usr/bin/env python # coding=utf-8 import os import shutil import time impo ...

  10. Python Batch auto cropping pictures

    """ use Pythonp Batch cropping pictures """ from PIL import Image import matplotlib.pyplot as ...

Random recommendation

  1. android tablelayout display picture

    When in tablelayout When the picture is shown in , Set up imageView For fixed size , There will be divide by zero error take LayoutParams Change it to TableRow.LayoutParams that will do ...

  2. Codeforces Round #FF (Div. 2)__E. DZY Loves Fibonacci Numbers (CF447) Line segment tree

    http://codeforces.com/contest/447/problem/E The question : Given an array , m operations , 1 l r It means interval modification , Every time a[i] +  Fibonacci[i-l ...

  3. 【 Changed the topological sort of the day 】POJ 1094——Sorting It All Out

    source : Click to open the link Don't know what's going on ,wa For a whole day .. In times of despair AC 了 . The key point is to deal with it step by step and judge the three situations . 1. Judge if it's a ring , The loop outputs error messages directly . 2. And then one side at a time , Topological sort , If ...

  4. actual combat DeviceIoControl A third : Make disk image file

    Q DOS command DISKCOPY It impressed me a lot , Now there are many " clone " Software , You can make a full copy of the disk . I think , To make a disk image file ,DeviceIoControl It should be very useful ? A yes ...

  5. Microservice architecture - be based on Harbor Build a local image warehouse

    Before written < build docker Local image warehouse and provide permission verification and UI Interface > article , Then a colleague commented that it was too complicated to do so , If Harbor To build it will be simpler and more powerful . So I took the time to study based on Harbor Construction version ...

  6. to dao Layer injection jdbcTemplate It's a compulsion bug(jdbcDaoSupport Don't use it casually ! Remember when you use it !)

    Record Dao It's a real mistake On this day I'm using Spring When you configure items with annotations , my Idea Throw me a mistake like this : Exception in thread "main" org ...

  7. oracle expdp Automatic backup scripts

    windows: @echo off echo ================================================ echo Windows In the environment Oracle Database automation ...

  8. javascript file

    DOM Document <html> Document object Every browser loaded with HTML Documents will become Document object . Document Object enables us to modify from script HTML page ...

  9. Linux operation redis Use (VMwareWorkstation)

    Projects are generally deployed to linux above , I remember when I first came out , The first company Server is windows System , In the future, the company's projects are all put in linux above , So master linux Some of the basic operation is a necessary knowledge for a programmer , How to use this record ...

  10. vue-router + ElementUI Realization NavMenu Navigation menu Switch the selected state

    elemen-ui Official website :http://element.eleme.io/#/zh-CN/component/menu Novice Xiaobai uses vue+element-ui Try to build a background management system , The effect is this , ...