def finish_response(self, app_iter):
        if not self.scale:
            self.start_response(self.status, self.headers)
            self.output = app_iter
            return

        CONTENT_LENGTH.delete(self.headers)
        inBuffer = StringIO()
        try:
            for s in app_iter:
                self.logger.debug("Writing %d bytes into image buffer." % len(s))
                inBuffer.write(s)
        finally:
            if hasattr(app_iter, 'close'):
                app_iter.close()

        rawImg = Blob()
        rawImg.data = inBuffer.getvalue()
        inBuffer.close()
        image = Image(rawImg)
        self.logger.debug("Scaling image to %s" % self.scaled_size)
        image.scale(self.scaled_size[0])
        image.write(self.outbuffer)

        content_length = self.outbuffer.length()
        CONTENT_LENGTH.update(self.headers, content_length)
        CACHE_CONTROL.update(self.headers, s_maxage=CACHE_CONTROL.ONE_HOUR)
        self.start_response(self.status, self.headers)
示例#2
0
    def finish_response(self, app_iter):
        if not self.scale:
            self.start_response(self.status, self.headers)
            self.output = app_iter
            return

        CONTENT_LENGTH.delete(self.headers)
        inBuffer = StringIO()
        try:
            for s in app_iter:
                self.logger.debug("Writing %d bytes into image buffer." %
                                  len(s))
                inBuffer.write(s)
        finally:
            if hasattr(app_iter, 'close'):
                app_iter.close()

        rawImg = Blob()
        rawImg.data = inBuffer.getvalue()
        inBuffer.close()
        image = Image(rawImg)
        self.logger.debug("Scaling image to %s" % self.scaled_size)
        image.scale(self.scaled_size[0])
        image.write(self.outbuffer)

        content_length = self.outbuffer.length()
        CONTENT_LENGTH.update(self.headers, content_length)
        CACHE_CONTROL.update(self.headers, s_maxage=CACHE_CONTROL.ONE_HOUR)
        self.start_response(self.status, self.headers)
示例#3
0
def rsr2png(rsrfile):
	rsr2pct(rsrfile)
	pictfile = os.path.splitext(rsrfile)[0]+".pct"
	try:
		thumb = Image(str(pictfile))
	except:
		print pictfile
		raise
	thumb.opacity(100)
	thumb.scale(91,91)
	thumb.write(str(os.path.splitext(rsrfile)[0]+".png"))
 def manipula_img(self, img_r, nmsuc):
     """Procesa la imagen adquirida en formato xwd y la trasforma en jpg"""
     image_final = self.dir_tmp + nmsuc + ".jpg"
     contador = 0
     if path.exists(image_final):
         contador += 1
         image_final = self.dir_tmp + nmsuc + "_" + str(contador) + ".jpg"
         if path.exists(image_final):
             image_final = self.comprueba_nombre(image_final, nmsuc)
     img = Image(img_r)
     img.scale("1024x768")
     img.write(image_final)
     exe(image_final, nmsuc)
示例#5
0
    def thumb(self, req):
        if self.mime_type.startswith('image') \
                and guess_extension(self.mime_type) in _image_exts:

            file_path = req.cfg.attachments_path + '/' + self.webname()
            img = Image(file_path.encode('utf-8'))

            width, height = req.cfg.attachments_thumb_size.get()
            img.scale(Geometry(width, height))

            thumb_path = req.cfg.attachments_thumb_path + '/' + self.webname()
            if not exists(dirname(thumb_path)):
                makedirs(dirname(thumb_path))
            img.write(thumb_path.encode('utf-8'))
def walk_menu(entry):
    if isinstance(entry, xdg.Menu.Menu) and entry.Show is True:
        map(walk_menu, entry.getEntries())
    elif isinstance(entry, xdg.Menu.MenuEntry) and entry.Show is True:
        # byte 1 signals another entry
        conn.sendall('\x01')
        img_path = icon_attr(entry.DesktopEntry).encode('utf-8')
        if img_path and os.path.isfile(img_path):
            try:
                # Create an empty image and set the background color to
                # transparent. This is important to have transparent background
                # when converting from SVG
                img = Image()
                img.backgroundColor(Color(0, 0, 0, 0xffff))
                img.read(img_path)
                # scale the image to 48x48 pixels
                img.scale(Geometry(48, 48))
                # ensure the image is converted to ICO
                img.magick('ICO')
                b = Blob()
                img.write(b)
                # icon length plus data
                conn.sendall(struct.pack('i', len(b.data)))
                conn.sendall(b.data)
            except Exception:
                conn.sendall(struct.pack('i', 0))
        else:
            conn.sendall(struct.pack('i', 0))

        name = entry.DesktopEntry.getName()
        # name length plus data
        conn.sendall(struct.pack('i', len(name)))
        conn.sendall(name)

        command = re.sub(' -caption "%c"| -caption %c',
                ' -caption "%s"' % name, entry.DesktopEntry.getExec())
        command = re.sub(' [^ ]*%[fFuUdDnNickvm]', '', command)
        if entry.DesktopEntry.getTerminal():
                command = 'xterm -title "%s" -e %s' % (name, command)

        # command length plus data
        conn.sendall(struct.pack('i', len(command)))
        conn.sendall(command)
示例#7
0
    def resize(self, req, width, height):
        file_path = req.cfg.attachments_path + '/' + self.webname()
        if self.mime_type.startswith('image') \
                and guess_extension(self.mime_type) in _image_exts:

            img = Image(file_path.encode('utf-8'))
            img.fileName(
                'image.'+self.file_name.encode('utf-8').split('.')[-1])
            size = img.size()

            blob = Blob()
            if width > size.width() and height > size.height():
                img.write(blob)
            else:
                img.scale(Geometry(width, height))
                img.write(blob)
            return blob.data
        elif guess_extension(self.mime_type) == '.svg':
            with open(file_path.encode('utf-8'), 'rb') as svg:
                return svg.read()
        else:
            req.log_error(self.mime_type)
            return None
示例#8
0
from PythonMagick import Image
bilde= Image("8x8","#33FFCC")
x=y=0
for i in range(0,4):
    bilde.pixelColor(i,1, "#993300")
for i in range(0,4):
    bilde.pixelColor(i,7, "#993300")
for i in range (2,4):
    bilde.pixelColor(i,3,"#993300")
for i in range (2,4):
    bilde.pixelColor(i,5,"#993300")
bilde.pixelColor(4,2, "#993300")
bilde.pixelColor(4,4, "#993300")
bilde.pixelColor(4,6, "#993300")
bilde.scale("200x200")
bilde.write("236.png")
示例#9
0
from PythonMagick import Image
photo = Image("9x9", "#0404B4")
x = y = 0
photo.pixelColor(2, 3, '#04B404')
photo.pixelColor(3, 2, '#04B404')
photo.pixelColor(4, 1, '#04B404')
photo.pixelColor(5, 2, '#04B404')
photo.pixelColor(6, 3, '#04B404')
photo.pixelColor(2, 5, '#04B404')
photo.pixelColor(3, 4, '#04B404')
photo.pixelColor(4, 3, '#04B404')
photo.pixelColor(5, 4, '#04B404')
photo.pixelColor(6, 5, '#04B404')
for i in range(2, 7):
    photo.pixelColor(i, 0, '#04B404')
for i in range(3, 6):
    photo.pixelColor(i, 7, '#04B404')
for i in range(2, 5):
    photo.pixelColor(8, i, '#04B404')
for i in range(2, 5):
    photo.pixelColor(0, i, '#04B404')
for i in range(5, 7):
    photo.pixelColor(i / 3, i, '#04B404')
photo.pixelColor(1, 1, '#04B404')
photo.pixelColor(7, 1, '#04B404')
photo.pixelColor(7, 5, '#04B404')
photo.pixelColor(6, 6, '#04B404')

photo.scale("200x200")
photo.write("239.png")
示例#10
0
from PythonMagick import Image
photo=Image("9x9", "#E65C00")
x=y=0
for i in range(1,7):
    photo.pixelColor(4,i,'#0404B4')
for i in range(3,6):
    photo.pixelColor(i,2,'#0404B4')
for i in range(2,7):
    photo.pixelColor(i,3,'#0404B4')
for i in range(2,7):
    photo.pixelColor(i,0,'#0404B4')
for i in range(3,6):
    photo.pixelColor(i,7,'#0404B4')
for i in range(2,5):
    photo.pixelColor(8,i,'#0404B4')
for i in range(2,5):
    photo.pixelColor(0,i,'#0404B4')
for i in range(5,7):
    photo.pixelColor(i/3,i,'#0404B4')
photo.pixelColor(1,1, '#0404B4')
photo.pixelColor(7,1, '#0404B4')
photo.pixelColor(7,5, '#0404B4')
photo.pixelColor(6,6, '#0404B4')

photo.scale("200x200")
photo.write("238.png")
示例#11
0
bilde.pixelColor(3,6, "#22ff44")
bilde.pixelColor(4,3, "#22ff44")
bilde.pixelColor(4,6, "#22ff44")
bilde.pixelColor(5,4, "#22ff44")
bilde.pixelColor(5,5, "#22ff44")
bilde.pixelColor(5,6, "#22ff44")
bilde.pixelColor(5,7, "#22ff44")
bilde.pixelColor(5,8, "#22ff44")
bilde.pixelColor(5,9, "#22ff44")
bilde.pixelColor(7,3, "#22ff44")
bilde.pixelColor(7,4, "#22ff44")
bilde.pixelColor(7,5, "#22ff44")
bilde.pixelColor(7,6, "#22ff44")
bilde.pixelColor(7,7, "#22ff44")
bilde.pixelColor(7,8, "#22ff44")
bilde.pixelColor(7,9, "#22ff44")
bilde.pixelColor(8,3, "#22ff44")
bilde.pixelColor(8,6, "#22ff44")
bilde.pixelColor(8,9, "#22ff44")
bilde.pixelColor(9,3, "#22ff44")
bilde.pixelColor(9,6, "#22ff44")
bilde.pixelColor(9,9, "#22ff44")
bilde.pixelColor(10,3, "#22ff44")
bilde.pixelColor(10,9, "#22ff44")

# 12x12 pixels palielina lidz 300x300
bilde.scale("300x300")

# Objektu 'bilde' ieraksata failaa
bilde.write("233.png")
示例#12
0
bilde.pixelColor( 7,3, "#eeff23")
bilde.pixelColor( 6,2, "#eeff23")

bilde.pixelColor( 5,1, "#eeff23")
bilde.pixelColor( 4,1, "#eeff23")
bilde.pixelColor( 3,1, "#eeff23")
bilde.pixelColor( 2,2, "#eeff23")
bilde.pixelColor( 1,3, "#eeff23")
bilde.pixelColor( 2,10, "#eeff23")
bilde.pixelColor( 7,2, "#eeff23")

bilde.pixelColor( 8,3, "#eeff23")
bilde.pixelColor( 9,4, "#eeff23")
bilde.pixelColor( 10,5, "#eeff23")






# 3x3 pixels palielina liidz 200x200
bilde.scale ("500x500")

#Objektu 'bilde' ieraksta failaa
bilde.write("233.png")