Пример #1
0
    def get_image_size(self, data):
        if isinstance(data, dict):
            img_file = data['name']
            img_path = data['path']
            if (exists("{}{}".format(img_path, img_file))
                    and isfile("{}{}".format(img_path, img_file))):
                if img_file[len(img_file) - 3:] == 'png' or 'jpg' or 'jpeg':
                    try:
                        img = Image.open("{}{}".format(img_path, img_file))
                        size = img.size
                        width = int(re.search("\d+", str(size[0])).group())
                        height = int(re.search("\d+", str(size[1])).group())

                        return {'status': "OK",
                                'message': "Original file is found",
                                'width': width,
                                'height': height
                                }

                    except IOError:
                        return {'status': "ERROR",
                                'message': "Original file is not found"
                                }
                else:
                    return {'status': "ERROR",
                            'message': "Original file is not supported: {}".format(img_file[len(img_file) - 3:])
                            }
Пример #2
0
    def conv_image(self, data):
        if isinstance(data, dict):
            img_file = data['name']
            img_path = data['path']
            new_format = data['format']
            new_width = data['width']
            new_height = data['height']
            size = new_width, new_height
            outfile = "{}{}{}".format(img_path, str(img_file[:len(img_file) - 3]), str(new_format.lower()))
            origfile = "{}{}".format(img_path, str(img_file))

            if (isinstance(data, dict)
                    and exists("{}{}".format(img_path, img_file)) is True
                    and isfile("{}{}".format(img_path, img_file)) is True
                    and outfile is not origfile):
                try:
                    if img_file[len(img_file) - 3:] == 'png' or 'jpg' or 'jpeg':
                        img = Image.open("{}{}".format(img_path, img_file))
                        img.thumbnail(size)
                        img.save(outfile, new_format)
                        return {'status': "OK",
                                'message': "Original file is converted to {}".format(
                                    outfile)}
                except IOError:
                    return {'status': "ERROR",
                            'message': "Original file is not changed"}
Пример #3
0
    def _make_thumbnail(self, filename, size):
        with closing(storage.get(self.filename)) as f:
            img = Image.open(f)
            if size != img.size:
                img = img.resize(size)

        buf = BytesIO()
        buf.name = filename
        img.save(buf)
        buf.seek(0)
        storage.put(filename, buf, overwrite=True)
Пример #4
0
    def create(cls, commit=True, url=None, recipe=None, **kwargs):
        filename = storage.upload(recipe.name, url)

        with closing(storage.get(filename)) as f:
            img = Image.open(f)
            w, h = img.size

        return super().create(commit,
                              filename=filename,
                              recipe=recipe,
                              _width=w,
                              _height=h,
                              **kwargs)
Пример #5
0
def add_folder_art(path):
    # need to check for valid art here (while loop?)
    # add command for global do not overwrite
    # check for JPGs
    art_file = os.path.join(path, 'folder.jpg')
    good_art = False
    if os.path.isfile(art_file):
        try:
            img = Image.open(art_file)
            good_art = True
        except IOError:
            good_art = False
            os.remove(art_file)
    if good_art is True:
        print art_file + ' found - ' + str(img.size) + 'px.  Overwrite?'
        if yes_no() is False:
            print 'using existing art'
        else:
            os.remove(art_file)
            download_art(path, art_file)
    elif os.path.isdir(path):
        download_art(path, art_file)
Пример #6
0
def add_folder_art(path):
    # need to check for valid art here (while loop?)
    # add command for global do not overwrite
    # check for JPGs
    art_file = os.path.join(path, 'folder.jpg')
    good_art = False
    if os.path.isfile(art_file):
        try:
            img = Image.open(art_file)
            good_art = True
        except IOError:
            good_art = False
            os.remove(art_file)
    if good_art is True:
        print art_file + ' found - ' + str(img.size) + 'px.  Overwrite?'
        if yes_no() is False:
            print 'using existing art'
        else:
            os.remove(art_file)
            download_art(path, art_file)
    elif os.path.isdir(path):
        download_art(path, art_file)
Пример #7
0
def list_info(track, folder):
    # for FLACs we don't print the zero padding that is actually in the track
    # number
    print track.file_name
    print track.pprint
    print 'Artist: ' + track.tag['artist']
    print 'Album Artist: ' + track.tag['album_artist']
    print 'Track#: ' + track.tag['track_number']
    print 'Title: ' + track.tag['title']
    print 'Album: ' + track.tag['album']
    print 'Year: ' + track.tag['year']
    print 'Genre: ' + track.tag['genre']
    art_file = os.path.join(folder, 'folder.jpg')
    if os.path.isfile(art_file):
        try:
            img = Image.open(art_file)
            print art_file + ' found - ' + str(img.size) + 'px.' + '\n\n'
        except IOError:
            print 'Unable to open cover art.  This may or may not be a problem.\
  Check cover art manually:'

            pwd = os.getcwd()
            os.chdir(folder)
            Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
            httpd = SocketServer.TCPServer(("", 9999), Handler)
            interfaces = netifaces.interfaces()
            for i in interfaces:
                if i == 'lo':
                    continue
                iface = netifaces.ifaddresses(i).get(netifaces.AF_INET)
                if iface is not None:
                    for j in iface:
                        print 'http://' + j['addr'] + ':9999/folder.jpg'
            print 'refresh page to continue...'
            httpd.handle_request()
            httpd.server_close()
            os.chdir(pwd)
Пример #8
0
def list_info(track, folder):
    # for FLACs we don't print the zero padding that is actually in the track
    # number
    print track.file_name
    print track.pprint
    print 'Artist: ' + track.tag['artist']
    print 'Album Artist: ' + track.tag['album_artist']
    print 'Track#: ' + track.tag['track_number']
    print 'Title: ' + track.tag['title']
    print 'Album: ' + track.tag['album']
    print 'Year: ' + track.tag['year']
    print 'Genre: ' + track.tag['genre']
    art_file = os.path.join(folder, 'folder.jpg')
    if os.path.isfile(art_file):
        try:
            img = Image.open(art_file)
            print art_file + ' found - ' + str(img.size) + 'px.' + '\n\n'
        except IOError:
            print 'Unable to open cover art.  This may or may not be a problem.\
  Check cover art manually:'
            pwd = os.getcwd()
            os.chdir(folder)
            Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
            httpd = SocketServer.TCPServer(("", 9999), Handler)
            interfaces = netifaces.interfaces()
            for i in interfaces:
                if i == 'lo':
                    continue
                iface = netifaces.ifaddresses(i).get(netifaces.AF_INET)
                if iface is not None:
                    for j in iface:
                        print 'http://' + j['addr'] + ':9999/folder.jpg'
            print 'refresh page to continue...'
            httpd.handle_request()
            httpd.server_close()
            os.chdir(pwd)
Пример #9
0
import requests
import time
from selenium import webdriver
from PilLite import Image
from io import BytesIO

url = "https://unsplash.com"

driver = webdriver.Firefox(executable_path=r'./geckodriver')
driver.get(url)

driver.execute_script("window.scrollTo(0,1000);")
time.sleep(5)
image_elements = driver.find_elements_by_css_selector("#gridMulti img")
i = 0

for image_element in image_elements:
    image_url = image_element.get_attribute("src")
    # Send an HTTP GET request, get and save the image from the response
    image_object = requests.get(image_url)
    image = Image.open(BytesIO(image_object.content))
    image.save("./images/image" + str(i) + "." + image.format, image.format)
    i += 1
Пример #10
0
#######################################
# an example using python to make some graphics.
# there i expirementing with lighting ray passes in concave sphere.
#######################################

from PilLite import Image
import math

size_h = 100
size_w = 100

π = math.pi

im = Image.new(size_w, size_h + 255, 'RGB', 0)

#sphere light from above
for X in range(size_w):
    for Y in range(size_h):
        x = (2 * X / size_w - 1.0)
        y = (Y / size_h)
        if x * x + y * y < 1.0:
            z = math.sqrt(1 - x * x - y * y)
            w = math.sqrt(z * z + x * x)
            color = math.sqrt(
                2 * w * math.sqrt(1 - w * w) * math.sqrt(1 - x * x)) / 3
            color_int = int(255 * math.fabs(color))
            im.put_pixel((X, Y),
                         0x010000 * color_int + 0x0100 * color_int + color_int)

for Y in range(size_h):
    for X in range(size_w):
Пример #11
0
def create_thumb(filename):
    uploaded_img_thumb = Image.open("/".join((app.config["UPLOADED_IMG_DEST"], filename)))
    uploaded_img_thumb.thumbnail(THUMBS_SIZE)
    uploaded_img_thumb.save("/".join((app.config["UPLOADED_THUMB_DEST"], filename)))
 def resize_im(self, im, osize):
     return np.array(Image.fromarray(im).resize(osize[::-1], Image.BICUBIC))