Dynamic Web album python write simple folder picture browsing tool,
I don't know if you have such an experience. If you view a gif image on a windows computer, IE is opened by default. What other inquiry items are displayed, Which is troublesome. To solve this problem, I wrote a simple image browsing tool in the folder.
Take a folder on an edisk as an example.
Implementation
Business Code
# Coding: utf-8import sysreload (sys) sys. setdefaultencoding ('utf8 ') # _ author _ = 'Guo pu' # _ date _ = '2017/5' # _ Desc _ = Automatic Generation of webpage album import OS # Haha, there was originally a walk Method in the standard library. In this way, obtain the image file in a folder. def getFiles (filepath): files = [] if OS. path. isdir (filepath): for file in OS. listdir (filepath): if OS. path. isdir (file): getFiles (file) elif file.endswith('.jpg ') or file.endswith('.png') or file.endswith('.gif '): files. append (filepath + str (file) elif OS. path. isfile (filepath): files. append (filepath) return files # All .jpg files under the specified directory. png. save the file ending with gif and complete the path to the list to output def recourse (filepat H): files = [] for fpathe, dirs, fs in OS. walk (filepath): for f in fs: if f.endswith('.jpg ') or f.endswith('.png') or f.endswith('.gif '): files. append (OS. path. join (fpathe, f) return files # generate the webpage source code file and specify def generate (files, shuffle = False ): template_start = '''
Summary
• Disadvantages:
The disadvantages of the scheme are obvious. It is not good enough to support Chinese characters because the large image is displayed in the form of hyperlinks, so garbled characters may occur.
Then there are advantages:
The advantage is not obvious, because if a folder contains many subfolders or images, it will be slow.
• Let's talk about the improvements.
◦ Introduces JQuery and adds double-click events to remove unwanted images.
◦ Uses multi-threaded code to accelerate the generation of web pages
Finally, I would like to say that although this is an entertaining little thing, it will certainly be helpful for us to make full use of our imagination and constantly improve our development.
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.