程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python completed the thousand map imaging of the original words of the League of heroes, which is too cool

編輯:Python

Kilogram imaging : use N Pieces of pictures put together to make a picture .undefined Realization principle : First, the image to be imaged is converted into mosaic image , Then replace the corresponding color block with the corresponding color image from the library .undefined Image processing in the gallery : Mark the mixed colors of each picture in the gallery , Used to replace the target color block , And record the characteristics of each image for imaging , Increase image quality .


0, origin


Delaware

Part of the picture

Hero alliance - Microblogging

I saw this message when I was blogging a long time ago , I was shocked by him , The picture is made up of LOL A combination of nearly a thousand skin pictures ( Is this using ps It's done , It's still spelled one by one , It shouldn't be possible ), Just yesterday, I suddenly remembered this thing , I decided to do one, too , Even if the action is taken . I found this article , Look at the composition of the picture , Decide to get all the skin pictures first ! Then it began again Reptiles

Running environment :Python3.6.5 , pycharm-2018-1-2 , win10


What are you waiting for , Look down

1. Reptilian thinking


  • The source of skin pictures , First, I went to the official website to find , Thought of the daoju city skin monopoly area , There are just all the pictures we need .
 Skin image source 
  • adopt F12 Lock the picture and get the first picture URL,
 obtain URL
  • And so on, you can get multiple skin URL, It is found that only the red box in the figure is different
URLS
  • Try this to change the number in the red box ( metaphysics ), After changing the last three (122015-->122001) when , Got another Nuo hand's skin , It can be basically determined that the last three are Skin number , The number in front is Hero number , And the skin number must be three digits , Thanks for this step The blogger , Let me be more sure of the feasibility of this Law .( This step took a long time )
  • See here, you may have some questions , Why not get the required picture directly URL Well ? Why bother to find rules ? Because this page turning website is special , When turning the page URL It doesn't change , So you can't get all the skin through common methods , Then it is estimated that someone will propose to use selenium Library to simulate people using the browser to get all the pictures , But this will cause the speed of crawling pictures to be greatly reduced , It can only be used as a bad policy ( In the process, I learned octopus , It is found that the principle is similar to selenium, It's the Sims who control the browser , Speed is also not allowed to look directly , Although it can climb close 98% Website ), When the blogger's ability is limited, he chose the journey of finding rules !undefined If you have a good way to solve this problem , You can put forward... In the comments section , Thank you very much. !
  • Next, when you know the law , So how to get the number of each different hero ? Guided by other bloggers , Find out LoL database There are all the heads of heroes in , adopt F12 Find it slowly , Found this js file !
Network

Look at the preview, You can get all hero numbers , And the test found that ! such as Ashe Aishi's first skin corresponding number should be 22001, therefore URL Namely , The test found that it was indeed successful !

preview

  • Okay , That's it. That's the end of web analysis , Finally, you can write code !

2, The code framework


  • 1, Get hero number and skin number ( explain : About the skin number, we didn't find the number of each hero's skin , So set it to find all 001 To 015 Pictures of the , Of course, there can be more 020 It's OK )
  • 2, Import numbers into pictures URL in , Generate Url_list.
  • 3, according to URL To download the corresponding picture , And save to local .

3, Complete code


import requests
import re
import os
# # # # # # # # # # # # # #
# title: obtain LOL Hero skin image #
# author: Simple books 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 ' Oh my god , 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(' picture URL To be successful ')
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 ' Oh my god , Failed to get picture !'
if __name__ == '__main__':
print('author: Simple books Wayne_Dream:')
print('https://www.jianshu.com/u/6dd4484b4741')
input(' Please enter any character to start crawling :')
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 , One moment please ...')
print(' stay ' + path + ' Check out ...')
DownloadPic(pic_name_list, Url_list)
print(' The picture has been downloaded. ')
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 , One moment please ...')
print(' stay ' + path + ' Check out ...')
DownloadPic(pic_name_list, Url_list)
print(' The picture has been downloaded. ')

The code is ugly , If you don't understand something, you can put it forward in the comment area , I'll get back to you in seconds !/ Serious face

Okay , So far, we have finished LOL Whole skin acquisition , The next most interesting step , Kilogram imaging !( At the end of the article, there is the address of Baidu online disk of the skin atlas I climbed to )


4, In the initial stage, we first use a foreign synthesis software


Software download address

  • If it doesn't open , Then search for “foto-mosaik-edda” Download it !

Windows Please select this

After opening, the interface is like this .

The first step is to create a gallery

Take the first step

1.1

1.2

Wait a moment

Choose the second step create photo mosaic

2.1

2.2

2.3

2.4

2.5, Pop up a warning point to confirm

design sketch

Local


Share how to use... When you have time python Realize the function of this software …………

If you find something wrong or don't understand , In the comments section , Let's talk !\

If the article helps you , give the thumbs-up + Focus on , Your support is my greatest motivation


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved