def get_verify_code(self): print('Start downloading the verification code...') url = 'http://pan.baidu.com/api/getvcode' payload = { 'prod': 'pan', 't': random.random(), 'bdstoken': 'null', 'channel': 'chunlei', 'clienttype': '0', 'web': '1', 'app_id': '250528', } resp = self.sess.get(url=url, params=payload, headers=self.headers) js = json.loads(resp.text) self.verify_code_str = js['vcode'] resp = self.sess.get( url='http://pan.baidu.com/genimage?%s' % self.verify_code_str, headers=self.headers ) # save verify code image_file = 'vcode-getlink.jpg' save_image(resp, image_file) open_image(image_file) self.verify_code_input = input('Please enter the verify code for get link(return change):')
def _get_qrcode(self): """ 缓存并展示登录二维码 :return: """ url = 'https://passport.suning.com/ids/qrLoginUuidGenerate.htm?image=true&yys=%s' % str( time.time() * 1000)[:-5] headers = { 'User-Agent': self.spider_session.get_user_agent(), 'Referer': 'https://passport.suning.com/ids/login', } logger.info('登录二维码地址: %s' % url) resp = self.session.get(url=url, headers=headers) if not response_status(resp): logger.info('获取二维码失败') return False save_image(resp, self.qrcode_img_file) logger.info('二维码获取成功,请打开苏宁APP扫描') open_image(self.qrcode_img_file) if global_config.getRaw('messenger', 'email_enable') == 'true': email.send('二维码获取成功,请打开京东APP扫描', "<img src='cid:qr_code.png'>", [email.mail_user], 'qr_code.png') return True
def _get_qrcode(self): """ 缓存并展示登录二维码 :return: """ url = 'https://qr.m.jd.com/show' payload = { 'appid': 133, 'size': 300, 't': str(int(time.time() * 1000)), } headers = { 'User-Agent': self.spider_session.get_user_agent(), 'Referer': 'https://passport.jd.com/new/login.aspx', } resp = self.session.get(url=url, headers=headers, params=payload) if not response_status(resp): logger.info('获取二维码失败') return False save_image(resp, self.qrcode_img_file) logger.info('二维码获取成功,请打开京东APP扫描') open_image(add_bg_for_qr(self.qrcode_img_file)) if global_config.getRaw('messenger', 'email_enable') == 'true': email.send('二维码获取成功,请打开京东APP扫描', "<img src='cid:qr_code.png'>", [email.mail_user], 'qr_code.png') return True
def _get_qrcode(self): """ 缓存并展示登录二维码 :return: """ url = 'https://qr.m.jd.com/show' payload = { 'appid': 133, 'size': 147, 't': str(int(time.time() * 1000)), } headers = { 'User-Agent': self.spider_session.get_user_agent(), 'Referer': 'https://passport.jd.com/new/login.aspx', } resp = self.session.get(url=url, headers=headers, params=payload) if not response_status(resp): logger.info('获取二维码失败') return False save_image(resp, self.qrcode_img_file) logger.info('二维码获取成功,请打开京东APP扫描') open_image(self.qrcode_img_file) return True
def _get_qrcode(self): """ 缓存并展示登录二维码 :return: """ url = 'https://qr.m.jd.com/show' payload = { 'appid': 133, 'size': 147, 't': str(int(time.time() * 1000)), } headers = { 'User-Agent': self.spider_session.get_user_agent(), 'Referer': 'https://passport.jd.com/new/login.aspx', } resp = self.session.get(url=url, headers=headers, params=payload) if not response_status(resp): logger.info('获取二维码失败') return False img_file_name = '{}{}'.format('./cookies/', self.qrcode_img_file) save_image(resp, img_file_name) logger.info('二维码获取成功,请打开京东APP扫描') open_image(img_file_name) if global_config.getRaw('messenger', 'email_enable') == 'true': receivers = global_config.getRaw('messenger', 'email_receiver') email.send('二维码获取成功,请打开京东APP扫描', "<img src='cid:./cookies/qr_code.png'>", receivers.split(','), img_file_name) return True
def login_tb(self, page): page.waitForTimeout(2000) page.goto('https://login.taobao.com/member/login.jhtml?redirectURL=http%3A%2F%2Fcart.taobao.com%2Fcart.htm%3F%26from%3Dmini') page.waitForSelector('.icon-qrcode') page.click('.icon-qrcode') page.waitForSelector('.qrcode-img') qrcode_div = page.querySelector('.qrcode-img') qrcode_div.screenshot(path=self.qr_code_img) open_image(self.qr_code_img) page.waitForSelector('#J_OrderList') if page.querySelector('#J_OrderList'): print('进入购物车成功')
def get_images(self, link_dict): if "picture" in link_dict: link_dict.update({"picture" : open_image(link_dict["picture"])}) if "source" in link_dict: link_dict.update({"source" : open_image(link_dict["source"])}) if "pic_square" in link_dict: link_dict.update({"pic_square" : open_image(link_dict["picture"])}) if "likes" in link_dict: for a in link_dict["likes"]: #["data"] a.update({"pic_square" : open_image(a["pic_square"])}) if "comments" in link_dict: for a in link_dict["comments"]: #["data"]: a.update({"pic_square" : self.get_user_picture(a["from"]["id"], dimension = "square")}) return link_dict
def run(path, namespace): im = util.open_image(path) if im is not None: mirrored_im = mirror(im, namespace.mirror_mode) util.save_image(mirrored_im, namespace.path, namespace.save_folder, namespace.save_as, namespace.mode, "mirrored", namespace.optimize, namespace.background)
def run(path, namespace): im = util.open_image(path) if im is not None: scaled_im = scale(im, namespace.scalar, namespace.resample) util.save_image(scaled_im, path, namespace.save_folder, namespace.save_as, namespace.mode, "scaled", namespace.optimize, namespace.background)
def run(path, namespace): im = util.open_image(path) if im is not None: im = swap(im, namespace.before_color, namespace.after_color) util.save_image(im, path, namespace.save_folder, namespace.save_as, namespace.mode, "colorswaped", namespace.optimize, namespace.background)
def run(path, namespace): im = util.open_image(path) if im is not None: fit_image = fit(im, namespace.width, namespace.height, namespace.color, namespace.resample) util.save_image(fit_image, namespace.path, namespace.save_folder, namespace.save_as, namespace.mode, "fit", namespace.optimize, namespace.background)
def main(args): image_paths = read_list(args.image_list) for path in image_paths: im = open_image(path) # resize for memory width, height = im.size if height > 800: im = im.resize((int(800 * width / height), 800)) width, height = im.size # use 2D-FAN detect landmarks fa = FaceAlignment(LandmarksType._2D, enable_cuda=True, flip_input=False, use_cnn_face_detector=True) try: landmarks = fa.get_landmarks(np.array(im))[-1] landmarks[:, 1] = height - landmarks[:, 1] except: continue # generate a contour curve with contour points hull = ConvexHull(landmarks) # draw landmarks lm = np.array(im) for i in range(landmarks.shape[0]): rr, cc = draw.circle(height - landmarks[i, 1].astype('int32'), landmarks[i, 0].astype('int32'), 5) lm[rr, cc, :] = np.array((255, 0, 0)) # create mask mask = np.zeros((height, width)) rr, cc = draw.polygon(height - landmarks[hull.vertices, 1], landmarks[hull.vertices, 0], mask.shape) mask[rr, cc] = 1 save = True if args.save == 'True' else False path = path[:-1] if path[:-1] == '/' else path image_name = path[path.rindex('/') + 1:-4] + '_contour_nocrf.png' show_result(lm, mask, np.tile((mask != 0)[:, :, np.newaxis], (1, 1, 3)) * im, save=save, filename='images/' + image_name) # add CRF #prob = np.concatenate(((1-mask)[np.newaxis,:,:]*0.9 + mask[np.newaxis, :, :]*0.1, mask[np.newaxis, :, :]*0.9 + (1-mask)[np.newaxis, :, :]*0.1), axis=0) prob = ndimage.gaussian_filter(mask * 1.0, sigma=5) prob = np.concatenate( ((1 - prob)[np.newaxis, :, :], prob[np.newaxis, :, :]), axis=0) map = CRF(prob, np.array(im)) image_name = path[path.rindex('/') + 1:-4] + '_contour_crf.png' show_result(im, map, np.tile((map != 0)[:, :, np.newaxis], (1, 1, 3)) * im, save=save, filename='images/' + image_name)
def run(path, namespace): im = util.open_image(path) if im is not None: resized_image = resize(im, namespace.width, namespace.height, namespace.resample) util.save_image(resized_image, path, namespace.save_folder, namespace.save_as, namespace.mode, "resized", namespace.optimize, namespace.background)
def run(path, namespace): im = util.open_image(path) if im is not None: inverted_im = invert(im) if inverted_im is None: return util.save_image(inverted_im, namespace.path, namespace.save_folder, namespace.save_as, namespace.mode, "inverted", namespace.optimize, namespace.background)
def image_from_connection(self): if "likes" in self: for like in self["likes"]: print like like.update({"pic_square" : open_image(like["pic_square"])}) if "comments" in self: print self["comments"], self for comment in self["comments"]: print comment, "<---Comment" self.analyze_from(comment["from"])
def run(path, namespace): im = util.open_image(path) if im is not None: util.save_image(im, path, namespace.save_folder, namespace.save_as, namespace.mode, "optimized", optimize=True, background=namespace.background)
def run(path, namespace): ## NOTE: By default, the image is grayscaled and saved as the original. # image's mode. To save as 'L' or 'LA' the user must pass them explicitily # with 'mode' optional argument. im = util.open_image(path) if im is not None: dessaturated_im = dessaturate(im) if dessaturated_im is None: return util.save_image(dessaturated_im, path, namespace.save_folder, namespace.save_as, namespace.mode, "dessaturated", namespace.optimize, namespace.background)
def test_open_image(mocked_PIL_Image): real_path = os.path.realpath("") ## Test opening image with supported extension image_path = "imagepath.jpg" path = os.path.join(real_path, image_path) util.open_image(path) mocked_PIL_Image.open.assert_any_call(path) # Reseting the calls mocked_PIL_Image.open.reset_mock() ## Test opening image with UNsupported extension image_path = "imagepath.ubs" path = os.path.join(real_path, image_path) util.open_image(path) mocked_PIL_Image.open.assert_not_called() # Reseting the calls mocked_PIL_Image.open.reset_mock() ## Test opening image with UPPERCASE extension image_path = "imagepath.JPG" path = os.path.join(real_path, image_path) util.open_image(path) mocked_PIL_Image.open.assert_any_call(path)
def _get_QRcode(self): url = 'https://qr.m.jd.com/show' payload = { 'appid': 133, 'size': 147, 't': str(int(time.time() * 1000)), } headers = { 'User-Agent': USER_AGENT, 'Referer': 'https://passport.jd.com/new/login.aspx', } resp = self.sess.get(url=url, headers=headers, params=payload) if not response_status(resp): print(get_current_time(), '获取二维码失败') return False QRCode_file = 'QRcode.png' save_image(resp, QRCode_file) print(get_current_time(), '二维码获取成功,请打开京东APP扫描') open_image(QRCode_file) return True
def _get_QRcode(self): url = 'https://qr.m.jd.com/show' payload = { 'appid': 133, 'size': 147, 't': str(int(time.time() * 1000)), } headers = { 'User-Agent': self.default_user_agent, 'Referer': 'https://passport.jd.com/new/login.aspx', } resp = self.session.get(url=url, headers=headers, params=payload) if not resp.ok: logger.info('获取二维码失败') return False QRCode_file = 'QRcode.png' save_image(resp, QRCode_file) logger.info('二维码获取成功,请打开京东APP扫描') open_image(QRCode_file) return True
def _get_auth_code(self, uuid): image_file = os.path.join(os.getcwd(), 'jd_authcode.jpg') url = 'https://authcode.jd.com/verify/image' payload = { 'a': 1, 'acid': uuid, 'uid': uuid, 'yys': str(int(time.time() * 1000)), } headers = { 'User-Agent': USER_AGENT, 'Referer': 'https://passport.jd.com/uc/login', } resp = self.sess.get(url, params=payload, headers=headers) if not response_status(resp): print('获取验证码失败') return '' save_image(resp, image_file) open_image(image_file) return input('验证码:')
def create_blur_image(image, radius, weight): img, width, height = open_image(image) image_data = get_image_data(img) new_image_data = get_image_data(img) new_color = [] for x in range(width): for y in range(height): image_data_submatrix, height_sub, width_sub = extract_submatrix(x, y, height, width, image_data.copy(), radius, weight) new_color = calculate_new_color(image_data_submatrix, weight, height_sub, width_sub) new_image_data[y][x] = new_color save_new_image(new_image_data, f'test-image-blur-radius-{radius}-weight-{weight}.png') print('Image successfully changed.')
def change_image_color(image): img, width, height = open_image(image) image_data = get_image_data(img) new_color = [] for color in ['red', 'green', 'blue']: for x in range(width): for y in range(height): r, g, b, alpha = img.getpixel((x, y)) if color == 'red': new_color = [r,0,0, alpha] elif color== 'green': new_color = [0,g,0, alpha] elif color == 'blue': new_color = [0,0,b, alpha] image_data[y][x] = new_color save_new_image(image_data, f"test-image-split-{color}.png") print('Images successfully saved.')
def run(path, namespace): im = util.open_image(path) if im is not None: info(im)
def run(path, namespace): im = util.open_image(path) if im is not None: colorinfo(im, namespace.box, namespace.pixel)
def get_photo(self): picture = open_image(self["source"]) self.update({"picture" : picture}) return picture
def get_picture(self): pic = open_image(self["picture"]) self.update({"thumbnail": pic}) return pic
def get_user_picture(self, user_id, dimension="square"): response = self.request(user_id, args = {"fields" : ["picture.type(square)"]}) return open_image(response["picture"]["data"]["url"])
def get_pic_square_from_uid(self, uid): url_pic = self.fql("select pic_square from user where uid = " + uid)[0] return open_image(url_pic["pic_square"])
def run(path, namespace): im = util.open_image(path) if im is not None: util.save_image(im, path, namespace.save_folder, namespace.save_as, namespace.mode, "converted", namespace.optimize, namespace.background)
def get_image(self, key): self.update({key : open_image(self[key])})