Python PIL.Image.fromstring() Examples

The following are 13 code examples for showing how to use PIL.Image.fromstring(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module PIL.Image , or try the search function .

Example 1
Project: Dindo-Bot   Author: AXeL-dev   File: tools.py    License: MIT License 6 votes vote down vote up
def screen_game(region, save_to=None):
	x, y, width, height = region
	try:
		raw = root.get_image(x, y, width, height, X.ZPixmap, 0xffffffff)
		if hasattr(Image, 'frombytes'):
			# for Pillow
			screenshot = Image.frombytes('RGB', (width, height), raw.data, 'raw', 'BGRX')
		else:
			# for PIL
			screenshot = Image.fromstring('RGB', (width, height), raw.data, 'raw', 'BGRX')
		if save_to is not None:
			screenshot.save(save_to + '.png')
	except:
		filename = save_to + '.png' if save_to is not None else None
		screenshot = pyautogui.screenshot(filename, region)
	return screenshot

# Return pixel color of given x, y coordinates 
Example 2
def dots(self):
        dotsF = numpy.zeros((156,208))
        dotsI = dotsF.astype('uint8')
        k = 10

        for i in range(0,155,1):
            for j in range(k,206,15):
#                print i,j
		    dotsI[i,j] = 255
		    k = k - 4
    	    if k < 0: k = k + 15

	return dotsI
# display it to see if it matches the Seek black dot hex pattern

#	zz = Image.fromstring("I", (208,156), dotsI, "raw", "I;8")
#	toimage(zz).show()
#        print dotsI
##################################################################### 
Example 3
Project: Computable   Author: ktraunmueller   File: videoreader.py    License: MIT License 5 votes vote down vote up
def _test():
    import EasyDialogs
    try:
        from PIL import Image
    except ImportError:
        Image = None
    import MacOS
    Qt.EnterMovies()
    path = EasyDialogs.AskFileForOpen(message='Video to convert')
    if not path: sys.exit(0)
    rdr = reader(path)
    if not rdr:
        sys.exit(1)
    dstdir = EasyDialogs.AskFileForSave(message='Name for output folder')
    if not dstdir: sys.exit(0)
    num = 0
    os.mkdir(dstdir)
    videofmt = rdr.GetVideoFormat()
    imgfmt = videofmt.getformat()
    imgw, imgh = videofmt.getsize()
    timestamp, data = rdr.ReadVideo()
    while data:
        fname = 'frame%04.4d.jpg'%num
        num = num+1
        pname = os.path.join(dstdir, fname)
        if not Image: print 'Not',
        print 'Writing %s, size %dx%d, %d bytes'%(fname, imgw, imgh, len(data))
        if Image:
            img = Image.fromstring("RGBA", (imgw, imgh), data)
            img.save(pname, 'JPEG')
            timestamp, data = rdr.ReadVideo()
            MacOS.SetCreatorAndType(pname, 'ogle', 'JPEG')
            if num > 20:
                print 'stopping at 20 frames so your disk does not fill up:-)'
                break
    print 'Total frames:', num 
Example 4
Project: python3_ios   Author: holzschu   File: test_image.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_fromstring(self):
        self.assertRaises(NotImplementedError, Image.fromstring) 
Example 5
Project: python3_ios   Author: holzschu   File: test_image_frombytes.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_not_implemented(self):
        self.assertRaises(NotImplementedError, Image.fromstring) 
Example 6
Project: nototools   Author: googlefonts   File: glyph_image_pair.py    License: Apache License 2.0 5 votes vote down vote up
def _fingerprint(data, frame, size):
    # python 2
    data_str = "".join(chr(p) for p in data)
    im = Image.fromstring("L", (frame.w, frame.h), data_str, "raw", "L", 0, 1)
    im = im.resize(size, resample=Image.BILINEAR)
    return list(im.getdata()) 
Example 7
Project: Tickeys-linux   Author: BillBillBillBill   File: img_pil.py    License: MIT License 5 votes vote down vote up
def save(filename, width, height, fmt, pixels, flipped=False):
        image = PILImage.fromstring(fmt.upper(), (width, height), pixels)
        if flipped:
            image = image.transpose(PILImage.FLIP_TOP_BOTTOM)
        image.save(filename)
        return True


# register 
Example 8
Project: Tickeys-linux   Author: BillBillBillBill   File: img_pil.py    License: MIT License 5 votes vote down vote up
def save(filename, width, height, fmt, pixels, flipped=False):
        image = PILImage.fromstring(fmt.upper(), (width, height), pixels)
        if flipped:
            image = image.transpose(PILImage.FLIP_TOP_BOTTOM)
        image.save(filename)
        return True


# register 
Example 9
Project: Splunking-Crime   Author: nccgroup   File: videoreader.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def _test():
    import EasyDialogs
    try:
        from PIL import Image
    except ImportError:
        Image = None
    import MacOS
    Qt.EnterMovies()
    path = EasyDialogs.AskFileForOpen(message='Video to convert')
    if not path: sys.exit(0)
    rdr = reader(path)
    if not rdr:
        sys.exit(1)
    dstdir = EasyDialogs.AskFileForSave(message='Name for output folder')
    if not dstdir: sys.exit(0)
    num = 0
    os.mkdir(dstdir)
    videofmt = rdr.GetVideoFormat()
    imgfmt = videofmt.getformat()
    imgw, imgh = videofmt.getsize()
    timestamp, data = rdr.ReadVideo()
    while data:
        fname = 'frame%04.4d.jpg'%num
        num = num+1
        pname = os.path.join(dstdir, fname)
        if not Image: print 'Not',
        print 'Writing %s, size %dx%d, %d bytes'%(fname, imgw, imgh, len(data))
        if Image:
            img = Image.fromstring("RGBA", (imgw, imgh), data)
            img.save(pname, 'JPEG')
            timestamp, data = rdr.ReadVideo()
            MacOS.SetCreatorAndType(pname, 'ogle', 'JPEG')
            if num > 20:
                print 'stopping at 20 frames so your disk does not fill up:-)'
                break
    print 'Total frames:', num 
Example 10
Project: captchacker2   Author: 00nanhai   File: break_captcha_utils.py    License: GNU General Public License v3.0 5 votes vote down vote up
def preprocess_captcha_part(file):
    letter_algo = []
    letters = split_captcha(file)
    
    for i in range (len(letters)):

        #letter = Image.fromstring("L", cv.GetSize(letters[i]), letters[i].tostring())
        letter = Image.open(letters[i])
        letter_algo.append(letter.point(lambda i: (i/255.)))

    return letters 
Example 11
Project: aws-builders-fair-projects   Author: aws-samples   File: pinned.py    License: Apache License 2.0 5 votes vote down vote up
def take_pic():
    video = v4l2capture.Video_device("/dev/video0")
    size_x, size_y = video.set_format(1280, 1024)
    video.create_buffers(1)
    video.queue_all_buffers()
    video.start()
    select.select((video,), (), ())
    image_data = video.read()
    video.close()
    image = Image.fromstring("RGB", (size_x, size_y), image_data)
    in_mem_file = io.BytesIO()
    logger.info("In_men_file pre saved size {}".format(len(in_mem_file.getvalue())))
    image.save(in_mem_file, "JPEG")
    logger.info("In_men_filepost saved size {}".format(len(in_mem_file.getvalue())))
    return in_mem_file 
Example 12
Project: Email_My_PC   Author: Jackeriss   File: capture.py    License: MIT License 5 votes vote down vote up
def getImage(self):
        buffer, width, height = self.dev.getbuffer()
        if buffer:
            im = Image.fromstring('RGB', (width, height), buffer, 'raw', 'BGR', 0, -1)
            return im 
Example 13
Project: pyseek   Author: Fry-kun   File: seek.py    License: MIT License 4 votes vote down vote up
def get_image():
    global im2arrF
    while True:
        # Send read frame request
        send_msg(0x41, 0x53, 0, 0, '\xC0\x7E\x00\x00')

        try:
            ret9  = dev.read(0x81, 0x3F60, 1000)
            ret9 += dev.read(0x81, 0x3F60, 1000)
            ret9 += dev.read(0x81, 0x3F60, 1000)
            ret9 += dev.read(0x81, 0x3F60, 1000)
        except usb.USBError as e:
            sys.exit()

        #  Let's see what type of frame it is
        #  1 is a Normal frame, 3 is a Calibration frame
        #  6 may be a pre-calibration frame
        #  5, 10 other... who knows.
        status = ret9[20]
        #print ('%5d'*21 ) % tuple([ret9[x] for x in range(21)])

        if status == 1:
            #  Convert the raw calibration data to a string array
            calimg = Image.fromstring("I", (208,156), ret9, "raw", "I;16")

            #  Convert the string array to an unsigned numpy int16 array
            im2arr = numpy.asarray(calimg)
            im2arrF = im2arr.astype('uint16')

        if status == 3:
            #  Convert the raw calibration data to a string array
            img = Image.fromstring("I", (208,156), ret9, "raw", "I;16")

            #  Convert the string array to an unsigned numpy int16 array
            im1arr = numpy.asarray(img)
            im1arrF = im1arr.astype('uint16')

            #  Subtract the calibration array from the image array and add an offset
            additionF = (im1arrF-im2arrF)+ 800

            #  convert to an image and display with imagemagick
            disp_img = toimage(additionF)
            #disp_img.show()
            
            return disp_img