Thousand image imaging: put together a picture with N pictures.
Implementation principle: first convert the image to be imaged into mosaic image, and then replace the corresponding color block with the image of the corresponding color from the gallery.
Picture processing in the Gallery: mark the mixed color of each picture in the gallery to replace the target color block, and record the characteristics of each picture for imaging to increase the imaging quality.
0, origin
Dreven
Picture part
Hero alliance - microblog
I saw this when I was brushing my microblog a long time ago. I was shocked by him. The picture is composed of nearly a thousand skin pictures of LOL (is it made of ps or spelled one by one? It should be impossible). Just yesterday, I suddenly remembered this thing and decided to do one, even if I took action. I found the article , after looking at the composition of the picture, I decided to get all the pictures of the skin first! Then began the reptile again!
- Operating environment: Python 3 6.5 , pycharm-2018-1-2 , win10
What are you doing? Look down
1. Reptile ideas
-
The source of skin pictures. First, I went to the official website and thought of it Daojucheng skin monopoly area , there are just all the pictures we need.
Skin image source
-
Lock the picture through F12 and obtain the URL of the first picture( https://game.gtimg.cn/images/daoju/app/lol/medium/2-122015-9.jpg)
obtain URL
-
By analogy, you can get multiple skin URL s. It is found that only the red box in the figure is different
URLS
-
Try to change the number (metaphysics) in the red box. When changing the last three digits (122015 – > 122001), you get another Nuo hand's skin. It can be basically determined that the last three digits are the skin number, the previous digit is the hero number, and the skin number must be three digits. Thank you for this step The blogger , let me be more sure of the feasibility of this law. (this step took a long time)
-
You may have some questions here. Why not get the URL of the required image directly? Why bother to find rules? Because this page turning website is special, the URL will not change during page turning, so it is impossible to obtain all skin through common methods. It is estimated that someone will propose to use selenium library to simulate people to obtain all pictures using the browser, but this will greatly reduce the speed of crawling pictures, It can only be used as a bad policy (I learned about octopus in this process and found that its principle is similar to selenium. It is an analog person who controls the browser, and the speed is not allowed to look directly. Although it can climb nearly 98% of websites), I chose the journey of finding rules when the blogger's ability is limited!
If you have a good way to solve this problem, you can put it forward in the comments. Thank you very much! -
Next, after knowing the rules, how to get the number of each different hero? Under the guidance of other bloggers, it is found that LoL database There are all heroes' avatars in F12. Through F12's slow search, I found this js file!
Network
Check its preview, you can get all hero numbers, and the test findings are available! For example, Ashe Aishi's first skin corresponding number should be 22001 according to the law, so the URL is https://game.gtimg.cn/images/daoju/app/lol/medium/2-22001-9.jpg , the test found that it was indeed successful!
preview
- Well, that's it, web analysis is over, and you can finally write code!
2. Code framework
- 1. Get the hero number and skin number (Note: the number of each hero's skin is not found for the skin number, so it is set to find all pictures from 001 to 015, of course, more 020 is also OK)
- 2. Import the number into the picture URL( https://game.gtimg.cn/images/daoju/app/lol/medium/2-******-9.jpg )Generate URL in_ list.
- 3. Download the corresponding picture according to the URL and save it locally.
3. Complete code
import requests import re import os # # # # # # # # # # # # # # # title:obtain LOL Hero skin image # # author:Jian Shu Wayne_Dream # # date:2018-7-5 # # Reprint please indicate the source!!! # # # # # # # # # # # # # # # def getHero_data(): try: headers = { 'user-agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36' } url = 'http://lol.qq.com/biz/hero/champion.js' r = requests.get(url, headers=headers) r.raise_for_status() r.encoding = r.apparent_encoding text = r.text hero_id = re.findall(r'"id":"(.*?)","key"', text) hero_num = re.findall(r'"key":"(.*?)"', text) return hero_id, hero_num except: return 'Lying slot, failed to obtain hero code!' def getUrl(hero_num): part1 = 'https://game.gtimg.cn/images/daoju/app/lol/medium/2-' part3 = '-9.jpg' skin_num = [] Url_list = [] for i in range(1, 21): i = str(i) if len(i) == 1: i = '00'+i elif len(i) == 2: i = '0'+i else: continue skin_num.append(i) for hn in hero_num: for sn in skin_num: part2 = hn + sn url = part1 + part2 + part3 Url_list.append(url) print('picture URL Get success') return Url_list def PicName(hero_id, path): pic_name_list = [] for id in hero_id: for i in range(1, 21): pic_name = path + id + str(i) + '.jpg' pic_name_list.append(pic_name) return pic_name_list def DownloadPic(pic_name_list, Url_list): count = 0 n = len(Url_list) try: for i in range(n): headers = { 'user-agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36' } res = requests.get(Url_list[i], headers=headers).content if len(res) < 100: count += 1 print('\r Current progress:{:.2f}%'.format(100*(count/n)), end='') else: with open(pic_name_list[i], "wb") as f: f.write(res) count += 1 print('\r Current progress:{:.2f}%'.format(100*(count/n)), end='') except: return 'Horizontal slot, failed to get picture!' if __name__ == '__main__': print('author:Jian Shu Wayne_Dream:') print('https://www.jianshu.com/u/6dd4484b4741') input('Please enter any character to start the crawler:') if os.path.exists('D:\LOLimg_wayne\\') == False: path = r'D:\LOLimg_wayne\\' os.mkdir(path) hero_id, hero_num = getHero_data() Url_list = getUrl(hero_num) pic_name_list = PicName(hero_id, path) print('Downloading pictures, please wait...') print('stay' + path + 'Next view...') DownloadPic(pic_name_list, Url_list) print('Picture download complete') else: path = r'D:\LOLimg_wayne\\' hero_id, hero_num = getHero_data() Url_list = getUrl(hero_num) pic_name_list = PicName(hero_id, path) print('Downloading pictures, please wait...') print('stay' + path + 'Next view...') DownloadPic(pic_name_list, Url_list) print('Picture download complete')
The code is ugly. If you don't understand it, you can put it forward in the comment area. I'll get back to you in seconds/ Serious face
Well, here we have completed the acquisition of LOL whole skin. Next, we will take the most interesting step, Qiantu imaging! (at the end of the article, there is the baidu online disk address of the skin atlas I climbed to)
4. In the initial stage, we first use a foreign synthesis software
- If you can't open it, search "foto mosaik Edda" to download it!
Please select this for Windows users
After opening, the interface is like this.
Step 1: create a gallery
Choose the first step first
1.1
1.2
Wait a minute
Select step 2 to create photo mosaic
2.1
2.2
2.3
2.4
2.5. Pop up the warning point for confirmation
design sketch
local
Have time to share how to use python to realize the functions of this software
If you find an error or don't understand, you can put it forward in the comment area for everyone to communicate\
If the article is helpful to you, like + pay attention, your support is my biggest motivation