In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces python how to achieve picture to Execl, picture to TXT tool, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
Install prerequisites
Note: it is recommended to run and execute the following command with administrator privileges during installation.
Install PIL Photo processing Library pip install pillow
Install the qrcode QR code processing tool pip install qrcode
Install openpyxl Execl form processing tool pip install openpyxl right menu add "copy file path" function Win7 system if you are using the Win7 system, you can save the following code as the copy file path .reg file, double-click run to add the registry, you can achieve one-click copy file path function.
Copy file path .reg
Windows Registry Editor Version 5.00; file [HKEY_CLASSES_ROOT\ *\ shell\ copypath] @ = "copy file path" [HKEY_CLASSES_ROOT\ *\ shell\ copypath\ command]; @ = "mshta _ vbscript:clipboarddata.setdata (\" text\ ",\"% 1\ ") (close)" with quotation marks; @ = "cmd.exe / c echo\"% 1\ "| clip"; without quotation marks @ = "cmd.exe / c echo% 1 | clip" Folder [HKEY_CLASSES_ROOT\ Directory\ shell\ copypath] @ = "copy folder path" [HKEY_CLASSES_ROOT\ Directory\ shell\ copypath\ command]; @ = "mshta _ vbscript:clipboarddata.setdata (\" text\ ",\"% 1\ ") (close)"; with quotation marks; @ = "cmd.exe / c echo\"% 1\ "| clip"; without quotation marks @ = "cmd.exe / c echo% 1 | clip"
Usage: right-click on any file or folder to select the copy file path, you can easily copy the file or folder path to the clipboard. As shown below:
Win10 system
The Win10 system comes with the replication path function.
Usage: first hold down the Shift key, and then right-click on any file or folder to select the copy path, you can easily copy the path of the file or folder to the clipboard. However, the replication result of Win10's own replication path function contains quotation marks, which need to be deleted manually as needed.
Picture to Execl tool
Overview
This is a Python gadget for converting pictures into Execl tables, using pillow, openpyxl, and other third-party libraries.
The principle is to open a picture, first convert the format of the picture to zoom, then read the RGB value of each pixel of the picture in turn, and then use the value as the background color of the corresponding cell in the Excel table. Finally, each cell is set to a small square with a height equal to its width. See the code notes for details.
source code
Py_img_to_excel.py
From openpyxl.workbook import Workbook# Import Workbook Library use and operate Execl workbook from openpyxl.styles import PatternFill,Color # Import PatternFill,Color Library use and operate Execl cells from PIL import Image# Import Image Library use and manipulate picture file import datetime# convert an integer value into a 26-ary string # because the row coordinates of execl cells are 26-ary, such as "A", "Z", "AA" "AZ" def dec_to_base26 (d): s = "" m = 0 while d > 0: M = d% 26 if m = = 0: M = 26 s = "{0 if c} {1 while s}" .format S) d = (d-m) / / 26 return s# converts a 26-ary string into an integer value def base26_to_dec (s): d = 0 j = 1 st = s.upper () for x in range (0, len (st)) [::-1]: C = ord (st [x]) if c
< 65 and c >90: return 0d + = (c-64) * j * = 26 return d # convert an integer coordinate to Execl coordinate # the row coordinate of the Execl coordinate is 26 ary, and the column coordinate is 10 ary, such as (AA, 100) def decxy_to_excelxy (x, y): return ("{0Execl s} {1D}" .format (dec_to_base26 (x)) Y) # convert the RGB value of a pixel to a hexadecimal string supported by Execl, such as "AARRGGBB", where AA represents transparency, which is set to 0 here, such as "00FF55FF" def pixel_to_xrgbstr (pix): return ("00 {0AA 02X} {1AA 02X}" .format (pix [0], pix [1], pix [2])) # Image to Execl function ImgName stands for full path picture name def image_to_excel (imgName): # create an excel workbook wb = Workbook () ws = wb.active # Open the picture file print ("Open Image File [{0}]" .format (imgName)) try: img = Image.open (imgName) except: print ("Error to Open [{0}]!!" .format (imgName) )) # determine the format of the picture file It must be in "RGB" format. If it is not "RGB" format, # is converted to "RGB" format with the convert function. If "RGB" >
To facilitate the use of this tool, instead of opening cmd to execute python py_img_to_excel.py commands manually every time, you can create a new Img2Excel.bat script file with the following script contents. Put the script file in the same folder as the py_img_to_excel.py file, then send the script file to the desktop shortcut, and then double-click the script file to run py_img_to_excel.py directly
Img2Excel.bat
@ echo offset cur_path= "% cd%\ py_img_to_excel.py" python% cur_path%pause
Operation method
Directly double-click the desktop Img2Excel.bat shortcut to run this tool, and then the program waits for the user to enter a picture file name with the full path, here you can use the just copied file path tool to directly copy the picture path and paste it.
Picture to TxT tool
Overview
This is a Python gadget for converting pictures into TXT files, using third-party libraries such as pillow.
The principle is to open a picture, first convert the format of the picture into a zoom, then binarize the image and convert it into a pure black and white image, then read the value of each pixel of the picture in turn and write it into the text file, and if the value is not 0, write @. Otherwise, write the space, see the code notes for details.
source code
Py_img_to_txt.py
The from PIL import Image# import Image library uses and manipulates the picture file import datetimedef image_to_txt (imgName): # to get the current time and convert it into the string timenow = datetime.datetime.now () timestr = timenow.strftime ("% Y-%m-%d-%H-%M-%S") # the generated Txt file is used as the file name namestr = "{0}-{1} .txt" .format (imgName) Timestr) # Open or create a TxT file txt = open (namestr, "w+") # Open the picture file print ("Open Image File [{0}]" .format (imgName)) try: img = Image.open (imgName) except: print ("Error to Open [{0}]!!" .format (imgName)) # determine the format of the picture file, which must be in "RGB" format If it is not in RGB format, # is converted to RGB format with the convert function. If "RGB" >
To facilitate the use of this tool, instead of opening cmd to execute python py_img_to_txt.py commands manually every time, you can create a new Img2Txt.bat script file with the following script contents. Put the script file and the py_img_to_txt.py file in the same folder, then send the script file to the desktop shortcut, and then directly double the script file can run py_img_to_txt.py directly
Img2Txt.bat
@ echo offset cur_path= "% cd%\ py_img_to_txt.py" python% cur_path%pause
Operation method
Directly double-click the desktop Img2Txt.bat shortcut to run this tool, and then the program waits for the user to enter a picture file name with the full path, here you can use the just copied file path tool to directly copy the picture path and paste it.
Thank you for reading this article carefully. I hope the article "how to convert pictures to Execl and pictures to TXT tools" shared by the editor will be helpful to everyone. At the same time, I also hope you can support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.