Since using Win10, When you start the machine, you will be amazed from time to time , Some of the recommended background pictures are really nice , Like the following :
Then I began to find ways on the Internet , How to download these pictures . Then there is a way , Is to go to an unknown file directory :C:\Users\ user name \AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets
Then I saw a bunch of messy documents , This is where these pictures exist .
These wallpapers should all be Win10 Downloaded from Microsoft Server , So different people have different computer wallpapers
These files have no suffix by default , Then we add the above file .jpg
You can only see the true face of Lushan Mountain in the picture , Of course, you can manually add the suffix here ;
You can also copy the appeal file to another location , such as E Discoid Wallpaper Under the table of contents , And then use cmd Batch rename tool , Enter the following command :
ren E:\Wallpaper\* *.jpg
Then you can see these pictures correctly . Sure = See the pictures with horizontal and vertical versions , They are computer terminal and mobile terminal respectively :
You'll see , There are usually two wallpapers for each picture , One is for 1920 * 1080 Horizontal screen desktop wallpaper with high resolution , One is for 1080 * 1920 Resolution vertical screen mobile desktop wallpaper .
Now you can use these pictures as desktop wallpaper for other computers or mobile phones .
Using shortcut keys WIN + R Open the following function Interface :
Enter the following values , Quickly open our folders :
%localappdata%\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets
Copy our article , Change file suffix , For example, I add here .png
:
As a programmer , How can you manually add suffixes to this file , insupportableness , So we use Python This scripting language to automate processing .
A Windows 10 PC
Python 3x
PIL Module For Python 3x
We need to read the current user name
# Set Environment Variablesusername = os.environ['USERNAME']
Assembly file path :
# All file urls file_urls = { "wall_src": "C:\\Users\\" + username + "\\AppData\\Local\\Packages\\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\\" + "LocalState\\Assets\\", "wall_dst": os.path.dirname(os.path.abspath(__file__)) + "\\Wallpapers\\", "wall_mobile": os.path.dirname(os.path.abspath(__file__)) + "\\Wallpapers\\mobile\\", "wall_desktop": os.path.dirname(os.path.abspath(__file__)) + "\\Wallpapers\\desktop\\" }
Copy out file :
# A method to import the wallpapers from src folder(dir_src) @staticmethod def copy_wallpapers(): w = Wallpaper w.time_gap("Copying Wallpapers") # Copy All Wallpapers From Src Folder To Dest Folder for filename in os.listdir(w.file_urls["wall_src"]): shutil.copy(w.file_urls["wall_src"] + filename, w.file_urls["wall_dst"])
Add file suffix :
# A method to Change all the Extensions @staticmethod def change_ext(): w = Wallpaper w.time_gap("Changing Extensions") # Look into all the files in the executing folder and change extension for filename in os.listdir(w.file_urls["wall_dst"]): base_file, ext = os.path.splitext(filename) if ext == "": if not os.path.isdir(w.file_urls["wall_dst"] + filename): os.rename(w.file_urls["wall_dst"] + filename, w.file_urls["wall_dst"] + filename + ".jpg")
The complete code is as follows :
import osimport shutilimport timefrom PIL import Imageclass Wallpaper: # Set Environment Variables username = os.environ['USERNAME'] # All file urls file_urls = { "wall_src": "C:\\Users\\" + username + "\\AppData\\Local\\Packages\\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\\" + "LocalState\\Assets\\", "wall_dst": os.path.dirname(os.path.abspath(__file__)) + "\\Wallpapers\\", "wall_mobile": os.path.dirname(os.path.abspath(__file__)) + "\\Wallpapers\\mobile\\", "wall_desktop": os.path.dirname(os.path.abspath(__file__)) + "\\Wallpapers\\desktop\\" } msg = ''' DDDDD OOOOO NN N EEEEEEE D D O O N N N E D D O O N N N E D D O O N N N EEEE D D O O N N N E D D O O N N N E DDDDD OOOOO N NN EEEEEEE ''' # A method to showcase time effect @staticmethod def time_gap(string): print(string, end='') time.sleep(1) print(".", end='') time.sleep(1) print(".") # A method to import the wallpapers from src folder(dir_src) @staticmethod def copy_wallpapers(): w = Wallpaper w.time_gap("Copying Wallpapers") # Copy All Wallpapers From Src Folder To Dest Folder for filename in os.listdir(w.file_urls["wall_src"]): shutil.copy(w.file_urls["wall_src"] + filename, w.file_urls["wall_dst"]) # A method to Change all the Extensions @staticmethod def change_ext(): w = Wallpaper w.time_gap("Changing Extensions") # Look into all the files in the executing folder and change extension for filename in os.listdir(w.file_urls["wall_dst"]): base_file, ext = os.path.splitext(filename) if ext == "": if not os.path.isdir(w.file_urls["wall_dst"] + filename): os.rename(w.file_urls["wall_dst"] + filename, w.file_urls["wall_dst"] + filename + ".jpg") # Remove all files Not having Wallpaper Resolution @staticmethod def extract_wall(): w = Wallpaper w.time_gap("Extracting Wallpapers") for filename in os.listdir(w.file_urls["wall_dst"]): base_file, ext = os.path.splitext(filename) if ext == ".jpg": try: im = Image.open(w.file_urls["wall_dst"] + filename) except IOError: print("This isn't a picture.", filename) if list(im.size)[0] != 1920 and list(im.size)[0] != 1080: im.close() os.remove(w.file_urls["wall_dst"] + filename) else: im.close() # Arrange the wallpapers into the corresponding folders @staticmethod def arr_desk_wallpapers(): w = Wallpaper w.time_gap("Arranging Desktop wallpapers") for filename in os.listdir(w.file_urls["wall_dst"]): base_file, ext = os.path.splitext(filename) if ext == ".jpg": try: im = Image.open(w.file_urls["wall_dst"] + filename) if list(im.size)[0] == 1920: im.close() os.rename(w.file_urls["wall_dst"] + filename, w.file_urls["wall_desktop"] + filename) elif list(im.size)[0] == 1080: im.close() os.rename(w.file_urls["wall_dst"] + filename, w.file_urls["wall_mobile"] + filename) else: im.close() except FileExistsError: print("File Already Exists!") os.remove(w.file_urls["wall_dst"] + filename) @staticmethod def exec_all(): w = Wallpaper w.copy_wallpapers() w.change_ext() w.extract_wall() w.arr_desk_wallpapers() print(w.msg) time.sleep(3)wall = Wallpaper()wall.exec_all()
Then directly on the console cmd Next , Direct input python warllpaper_extract.py
, However, the following errors may occur :
resolvent : Module not found PIL
, We can use pip install Pillow
To install :
After successful installation , Re execution
Picture extraction complete , And it can separate the pictures on the desktop from those on the mobile phone ,
spot desktop Next , Successfully see the picture we want , congratulations , Once you find a new lock screen wallpaper next time , You can run this Python Script , Then go to choose your favorite photos :
So far, we have gone from manually obtaining pictures to using Python Automation , And through this article you can learn Python Of PIL Modules and static methods . Okay , See you in the next article !