-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merged the resize folder with bing module
- Loading branch information
1 parent
118776f
commit 0153d4d
Showing
4 changed files
with
408 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,14 +4,31 @@ | |
import imghdr | ||
import posixpath | ||
import re | ||
from resize.resize import resize | ||
from resize.resize import image_to_byte_array | ||
from PIL import Image | ||
from io import BytesIO | ||
import io | ||
|
||
|
||
''' | ||
Python api to download image form Bing. | ||
Author: Guru Prasad ([email protected]) | ||
''' | ||
|
||
def image_to_byte_array(image: Image) -> bytes: | ||
imgByteArr = io.BytesIO() | ||
image.save(imgByteArr, format="PNG") | ||
imgByteArr = imgByteArr.getvalue() | ||
return imgByteArr | ||
|
||
|
||
def resize(url,size: tuple): | ||
|
||
response = urllib.request.urlopen(url) | ||
img = Image.open(BytesIO(response.read())) | ||
img=img.resize(size=size,resample=Image.LANCZOS) | ||
#kl=image_to_byte_array(img) | ||
# with open('pn.png','wb') as f: | ||
# f.write(kl) | ||
return img | ||
|
||
class Bing: | ||
def __init__(self, query, limit, output_dir, adult, timeout, filter='',resize=None, verbose=True): | ||
|
@@ -28,7 +45,7 @@ def __init__(self, query, limit, output_dir, adult, timeout, filter='',resize=No | |
self.limit = limit | ||
assert type(timeout) == int, "timeout must be integer" | ||
self.timeout = timeout | ||
assert type(resize)==tuple, "resize must be a tuple(height,width)" | ||
assert (type(resize)==tuple) or (resize is None), "resize must be a tuple(height,width)" | ||
self.resize=resize | ||
|
||
# self.headers = {'User-Agent': 'Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0'} | ||
|
Oops, something went wrong.