Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys, os, io
- import json
- import urllib.request
- from PIL import Image
- from bs4 import BeautifulSoup
- source = sys.argv[1]
- page = urllib.request.urlopen(source).read()
- soup = BeautifulSoup(page, 'html.parser')
- item = soup.find('',{'class':'pages'})
- last_item = item.find_all('div')[-2]
- cPage = int(last_item['data-ptimg'][5:9])
- for c in range(1, cPage + 2):
- #Open the image at given URL plus the image
- with urllib.request.urlopen(source + '/data/' + f'{c:04}' + '.jpg') as url:
- f = io.BytesIO(url.read())
- im = Image.open(f)
- #Open the corresponding JSON
- with urllib.request.urlopen(source + '/data/' + f'{c:04}' + '.ptimg.json') as url:
- j = io.BytesIO(url.read())
- data = json.load(j)
- #Create the new image
- out = Image.new('RGB', (data['views'][0]['width'], data['views'][0]['height']))
- #Descramble based off of JSON
- for i in data['views'][0]['coords']:
- src = i[2:].split(',', 1)
- srcX = src[0]
- srcY = src[1].split('+', 1)
- fWidth = srcY[1].split(',', 1)
- fHeight = fWidth[1].split('>', 1)
- dest = fHeight[1].split(',')
- out.paste(im.crop((int(srcX), int(srcY[0]), int(srcX) + int(fWidth[0]), int(srcY[0]) + int(fHeight[0]))), (int(dest[0]), int(dest[1])))
- #Give status updates
- print(f'{c:04}' + '.png')
- #Modify this line if you want to save in a different location or namespace
- out.save(f'{c:04}' + '.png', format='PNG', optimize=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement