Thousands of images: N images pieced together into a picture. Implementation principle: the first image to be transformed into Mosaic pictures, and then from the gallery with the corresponding color of the picture to replace the corresponding color block. Image processing in the gallery: Mark the mixed color of each image in the gallery to replace the target color block, and record the features of each image for imaging to increase the quality of imaging.


Origin of zero,



DE levin,

Pictures of local

League of Legends – Weibo

I saw this post a long time ago when I was surfing Weibo, and I was shocked by it. The picture is composed of LOL and nearly a thousand skin pictures (is it made by PS or pieced together one by one? It is impossible). I suddenly remembered this thing yesterday, so I decided to make one of them, and then I took action. Found this article, looked at the composition of the picture, decided to get all the skin pictures again! And the crawler began again!

  • Run environment: Python3.6.5, Pycharm -2018-1-2, win10

What are you doing? Look down

1. Crawler thinking

  • First of all, I went to the official website to find the source of the skin pictures, thinking of the Daojucheng skin sales area, which just has all the pictures we need.

Source of skin imagesCopy the code
  • Lock pictures made by F12 URL, the first picture (game. Gtimg. Cn/images/daoj…).

Get the URLCopy the code
  • The same can be done for multiple skin urls, with only the red boxes in the image being different

URLS
Copy the code
  • Try this change the number of red box (metaphysics), after changing the three (122015 – > 122001), received another hand skin, basic can be determined after three Numbers for skin and the preceding digit number as a hero, and skin number must be three, this step is to thank the blogger, let me more determined the feasibility of this law. (This took a long time.)
  • Looking at this, you might wonder, why not just get the URL for the image you want? Why bother looking for patterns? Because this page-turning site is special, the URL will not change when the page is turned, so it can not get all the skin through the common method, it is estimated that someone will put forward to useseleniumLibrary to simulate a person using a browser to get all the images, but this will cause the speed of image crawling to be greatly reduced, which can only be used as a backstop (learned during this process)octopus, found that its principle is similar to Selenium, in that it simulates human control of the browser and is also untouchable at speed, although it can climb nearly 98 percent of websites.)

    If you have a good solution to this problem, feel free to post it in the comments, thanks a lot!
  • Now that we know the rules, how do we get the number of each different hero? Under the guidance of other bloggers, I found all the heroes’ avatars in the LoL database. I found this JS file through slow search of F12!

Network
Copy the code

Check out preview to get all the hero numbers and test them out! Such as Ashe, the first skin athey corresponding number according to the law should be 22001, so the URL is game. Gtimg. Cn/images/daoj… “And the test found it was a success!

preview

  • Well, that’s it, that’s the end of page analysis, and you can finally write code!

2. Code framework

  • 1, get the hero and skin numbers (note: the number of skin numbers for each hero is not found, so set it to find all images from 001 to 015, of course you can also find more 020 images)
  • 2, the number will import image URL (game. Gtimg. Cn/images/daoj…). In, generate Url_list.
  • 3. Download the corresponding image according to the URL and save it locally.

3. Complete code

Import requests import re import OS # # # # # # # # # # # # # # # title: get LOL hero skin image # # author: Wayne_Dream # # 2018-7-5 # # reproduced 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 'Geez, failed to get 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(' hero_id ') return Url_list def PicName(hero_id, 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], Format (100*(count/n)), end= "") else: if len(res) < 100: count += 1 print(' format(100*(count/n)), end=" ") else: with open(pic_name_list[i], "wb") as f: Format (100*(count/n)), end='') except: return '. ' if __name__ == '__main__': Print (' Wayne_Dream: author: Jane books') print (' https://www.jianshu.com/u/6dd4484b4741 ') input (' please enter any character start crawler: ') the 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('... ') print(' on '+ path +' ') DownloadPic(pic_name_list, Url_list) print(pic_name_list) 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('... ') print(' on '+ path +' ') DownloadPic(pic_name_list, Url_list) print(' DownloadPic completed ')Copy the code

The code is ugly, if you can’t understand the part can be put forward in the comment area, I will reply to you in seconds! / serious face

Ok, now that we have completed the whole skin of LOL, let’s move on to the most interesting step, thousands of images! (At the end of the article I crawled to the skin atlas Baidu network disk address)


4. In the initial stage, we will use a foreign synthetic software

Software Download Address

  • If you can’t open it, just search “foto-Mosaik-edda” to download it!

Windows users please select this one

When I open it, the interface looks like this.

The first step is to create the gallery

Take the first step

1.1

1.2

Wait for a while

And then create Photo Mosaic

2.1

2.2

2.3

2.4

2.5. Pop-up warning point confirmation

rendering

local


When you have time to share how to implement this software in Python ………… If found wrong or do not understand the place, can put forward in the comment area, we communicate together! \

If the article is helpful to you, click like + follow, your support is my biggest motivation