コード例 #1
0
def saveFile() :
    global window, canvas, paper, filename, inImageR, inImageG, inImageB, outImageR, outImageG, outImageB, inW, inH, outW, outH
    draw = Drawing() # 빈 판을 준비

    saveFp = asksaveasfile(parent=window, mode='w', defaultextension='.png'
      ,filetypes = (("그림파일", "*.gif;*.jpg;*.png;*.tif;*.bmp"), ("모든파일", "*.*")))

    # 빈 판에 칼라찍기. '#000000~#FFFFFF'
    for  i  in range(outH) :
        for k in range(outW) :
            dataR = outImageR[i][k];dataG = outImageG[i][k];dataB = outImageB[i][k];
            hexStr = '#'
            if dataR > 15 :
                hexStr += hex(dataR)[2:]
            else :
                hexStr += ( '0' + hex(dataR)[2:] )
            if dataG > 15 :
                hexStr += hex(dataG)[2:]
            else :
                hexStr += ( '0' + hex(dataG)[2:] )
            if dataB > 15 :
                hexStr += hex(dataB)[2:]
            else :
                hexStr += ( '0' + hex(dataB)[2:] )
            draw.fill_color = Color(hexStr)
            draw.color(k, i, 'replace')

    with Image(filename=filename) as img :
        draw(img)
        img.save(filename=saveFp.name)

    print('Save... OK!')
コード例 #2
0
ファイル: quiz12-1.py プロジェクト: cutz-j/TodayILearned
def saveFile():
    global window, canvas, paper, filename, inImage, outImage, inW, inH, outW, outH
    draw = Drawing()  # 빈 판
    # 빈 판에 컬러 -> #000000 ~ #FFFFFF
    saveFp = asksaveasfile(parent=window,
                           mode='w',
                           defaultextension='.png',
                           filetypes=(("그림파일",
                                       "*.gif;*.jpg;*.png;*.tif;*.bmp"),
                                      ("모든파일", "*.*")))
    for i in range(outW):
        for j in range(outH):
            dataR = outImage[i][j][0]
            dataG = outImage[i][j][1]
            dataB = outImage[i][j][2]
            hexStr = '#'
            if dataR > 15:
                hexStr += hex(dataR)[2:]
            else:
                hexStr += ('0' + hex(dataR)[2:])
            if dataG > 15:
                hexStr += hex(dataG)[2:]
            else:
                hexStr += ('0' + hex(dataG)[2:])
            if dataB > 15:
                hexStr += hex(dataB)[2:]
            else:
                hexStr += ('0' + hex(dataB)[2:])
            draw.fill_color = Color(hexStr)
            draw.color(j, i, 'replace')
    with Image(filename=filename) as img:
        draw(img)
        img.save(filename=saveFp.name)
    print("SAVE OK")
コード例 #3
0
def replaceColorsInImage(img, color1, color2):
    ldraw = Drawing()
    ldraw.fill_color = color2
    width, height = img.size
    for x in range(0, width):
        for y in range(0, height):
            if img[x, y] == color1:
                ldraw.color(x, y, 'replace')
    ldraw(img)
コード例 #4
0
ファイル: ProoferBox.py プロジェクト: avtobiff/virtualagc
def replaceColorsInImage(img, color1, color2):
	ldraw = Drawing()
	ldraw.fill_color = color2
	width, height = img.size
	for x in range(0, width):
		for y in range(0, height):
			if img[x,y] == color1:
				ldraw.color(x, y, 'replace')
	ldraw(img)
コード例 #5
0
    def draw_lip(self, top=False, bottom=False):
        if "back" not in self.faces:
            return None

        if not (top ^ bottom): # 1 and only 1 of top or bottom should be true
            return None

        # First draw a full mask with the lip shape
        lip_full_mask_image = Image(width=math.ceil(self.tuckbox['width'] * POINT_PER_MM),
                                    height=math.ceil(self.lip_size() * POINT_PER_MM))
        lip_full_draw = Drawing()

        lip_full_draw.scale(POINT_PER_MM, POINT_PER_MM)

        # This cannot be too "thin" or the floodfill later would spill over
        lip_full_draw.stroke_width = max(2 / POINT_PER_MM, RESOLUTION / (200 * POINT_PER_MM))

        lip_full_draw.fill_color = Color('white')
        lip_full_draw.color(0, 0, 'reset')
        lip_full_draw.draw(lip_full_mask_image)

        lip_full_draw.stroke_color = Color('black')

        # 1/2 left of lip
        lip_full_draw.bezier([(0, self.lip_size()),
                              (0, self.lip_size() - .75*self.lip_size()),
                              (.2 * self.tuckbox['width'],
                               self.lip_size() - self.lip_size()),
                              (.5 * self.tuckbox['width'], self.lip_size() - self.lip_size())])

        # 1/2 right of lip
        lip_full_draw.bezier([(self.tuckbox['width'], self.lip_size()),
                              (self.tuckbox['width'],
                               self.lip_size() - .75*self.lip_size()),
                              (.8 * self.tuckbox['width'],
                               self.lip_size() - self.lip_size()),
                              (.5 * self.tuckbox['width'], self.lip_size() - self.lip_size())])

        lip_full_draw.draw(lip_full_mask_image)

        lip_full_draw.fill_color = Color('black')
        lip_full_draw.border_color = Color('black')
        lip_full_draw.color(.5 * self.tuckbox['width'],
                            0.8*self.lip_size(), 'filltoborder')

        lip_full_draw.draw(lip_full_mask_image)

        if self.faces['back'][:1] == "#":
            lip_image = Image(width = lip_full_mask_image.width, height = lip_full_mask_image.height,
                            background = Color(self.faces['back']))
        else:
            # Prepare the front image
            angle = 180 if "back_angle" not in self.options else (self.options["back_angle"]+2)*90

            if bottom:
                angle = (angle + 180) % 360

            _, file_extension = os.path.splitext(self.faces['back'])
            tmp_file = tempfile.NamedTemporaryFile(delete=False, suffix=file_extension)
            self.resize_rotate_image(self.faces['back'], tmp_file.name, angle, math.ceil(self.tuckbox['width'] * POINT_PER_MM),
                            math.ceil(self.tuckbox['height'] * POINT_PER_MM))
            lip_image = Image(filename=tmp_file.name)
            lip_image.crop(top=lip_image.height - lip_full_mask_image.height)

        # u = image pixel
        # h = height
        # j = row
        # Radius of the hold is {self.tuckbox['width']*.1}
        # if value is 1 (or more_, it's white
        # Top is the tip of the lip, bottom is attached to the box
        # finger_hold_size_save is the row # at which it should be no attenuation below
        finger_hold_size_save = str(
            int(lip_image.height - math.ceil(self.tuckbox['width'] * POINT_PER_MM * 0.1)))
        lip_image = lip_image.fx(
            "j>"+finger_hold_size_save+"?u:1+(u-1)*(j/"+finger_hold_size_save+")")

        lip_image.composite(operator='lighten', image=lip_full_mask_image)

        if bottom:
            lip_image.rotate(180)

        return lip_image