Пример #1
0
 def drawrect(self, row, col):
     draw = Drawing()
     draw.fill_color = Color('black')
     (x, y), (x2, y2) = self.pixel_box(row, col)
     for r in range(self.box_size):
         line_y = y + r
         draw.line((x, line_y), (x2, line_y))
         draw(self._img)
Пример #2
0
def create_line_img(x_start, x_finish, brush_width, params, img, filename):
    step = 1.01
    draw_img = Drawing()
    draw_img.stroke_color = Color("white")
    draw_img.fill_color = Color("white")
    draw_img.stroke_width = brush_width
    if x_start > x_finish:
        buf = x_start
        x_start = x_finish
        x_finish = buf
    x = x_start + step
    for i in range(3):
        while x < x_finish:
            x1 = x - step
            y1 = chosen_func(x1, params)
            y2 = chosen_func(x, params)
            draw_img.line((x1, y1), (x, y2))
            x = x + 2 * step
        step -= 0.5
        x = x_start + step
    draw_img.draw(img)
    img.save(filename=filename)
Пример #3
0
from wand.drawing import Drawing
Пример #4
0
draw = Drawing()
evilColor = Color("#FF00FF")
extraColor = Color("#FF8000")
draw.stroke_color = evilColor
draw.stroke_width = 4
draw.fill_opacity = 0

# Draw empty frames around all of the rejected boxes.
for i in range(0, len(rejectedBoxes)):
    boxFields = rejectedBoxes[i].split()
    boxLeft = int(boxFields[1])
    boxBottom = backgroundHeight - 1 - int(boxFields[2])
    boxRight = int(boxFields[3])
    boxTop = backgroundHeight - 1 - int(boxFields[4])
    draw.line((boxLeft, boxTop), (boxRight, boxTop))
    draw.line((boxLeft, boxBottom), (boxRight, boxBottom))
    draw.line((boxRight, boxTop), (boxRight, boxBottom))
    draw.line((boxLeft, boxTop), (boxLeft, boxBottom))

# Loop on lines on the selected page.  We're going to assume that the boxes are
# in 1-to-1 correspondence with the binsource digit, in the order read from
# disk, except that there may be less boxes (on the last page of a bank).
row = 0
lastRight = 1000000
boxIndex = 0
for index in range(startIndex, endIndex):
    if boxIndex >= len(boxes):
        print 'Out of boxes on page'
        break
    # Loop on the octal digits in the row.
Пример #5
0
draw = Drawing()
evilColor = Color("#FF00FF")
extraColor = Color("#FF8000")
draw.stroke_color = evilColor
draw.stroke_width = 4
draw.fill_opacity = 0

# Draw empty frames around all of the rejected boxes.
for i in range(0,len(rejectedBoxes)):
	boxFields = rejectedBoxes[i].split()
	boxLeft = int(boxFields[1])
	boxBottom = backgroundHeight - 1 - int(boxFields[2])
	boxRight = int(boxFields[3])
	boxTop = backgroundHeight - 1 - int(boxFields[4])
	draw.line((boxLeft,boxTop), (boxRight,boxTop))
	draw.line((boxLeft,boxBottom), (boxRight,boxBottom))
	draw.line((boxRight,boxTop), (boxRight,boxBottom))
	draw.line((boxLeft,boxTop), (boxLeft,boxBottom))

# Loop on lines on the selected page.  We're going to assume that the boxes are
# in 1-to-1 correspondence with the binsource digit, in the order read from 
# disk, except that there may be less boxes (on the last page of a bank).
row = 0
lastRight = 1000000
boxIndex = 0
for index in range(startIndex, endIndex):
	if boxIndex >= len(boxes):
		print 'Out of boxes on page'
		break
	# Loop on the octal digits in the row.
Пример #6
0
# Prepare a drawing-context.
draw = Drawing()
evilColor = Color("#FF00FF")
extraColor = Color("#FF8000")
draw.stroke_color = evilColor
draw.stroke_width = 4 * scale
draw.fill_opacity = 0

# Draw empty frames around all of the rejected boxes.
for i in range(0, len(rejectedBoxes)):
    boxTop = rejectedBoxes[i]['boxTop']
    boxBottom = rejectedBoxes[i]['boxBottom']
    boxLeft = rejectedBoxes[i]['boxLeft']
    boxRight = rejectedBoxes[i]['boxRight']
    draw.line((boxLeft, boxTop), (boxRight, boxTop))
    draw.line((boxLeft, boxBottom), (boxRight, boxBottom))
    draw.line((boxRight, boxTop), (boxRight, boxBottom))
    draw.line((boxLeft, boxTop), (boxLeft, boxBottom))

# Loop on lines on the selected page.
row = 0
boxIndex = 0
draw.stroke_color = extraColor
for row in range(0, len(lines)):
    if boxIndex >= len(boxes):
        if boxIndex < 1:
            top = 0
        else:
            #print 'Out of boxes in page, on row', row
            top = boxes[boxIndex - 1]['boxBottom']
Пример #7
0
def slice03():
    full_slice = new_blank_png(595, 182)

    # Two solid-colour areas, one on left and one on right
    #
    left_field = new_blank_png(299, 182, color=Color('rgb(44,128,64)'))
    right_field = new_blank_png(297, 182, color=Color('rgb(127,184,141)'))
    full_slice.composite(left_field, 0, 0)
    full_slice.composite(right_field, 299, 0)
   
    draw = Drawing()

    # Text on the left field
    #
    draw.font = FONT_BOLD
    draw.font_size = 18
    draw.fill_color = Color('white')
    draw.text(30, 85, "Smartphone Babyproofing")

    # Unfortunately don't yet have strokewidth
    #
    draw.line((29,95), (298,95))
    draw.line((29,96), (298,96))
    draw.line((29,97), (298,97))

    draw.font = FONT_REGULAR
    draw.font_size = 18
    draw.text(30, 125, "Tips on how to use those")
    draw.text(30, 147, "safety features you")
    draw.text(30, 169, "always forget to enable...")

    # Text on the right field
    #
    draw.font = FONT_BOLD
    draw.font_size = 18
    draw.fill_color = Color('black')
    draw.text(328, 85, "School savings")

    # Yada yada yada ...
    #
    draw.line((328,95), (595,95))
    draw.line((328,96), (595,96))
    draw.line((328,97), (595,97))

    draw.font = FONT_REGULAR
    draw.font_size = 18
    draw.text(328, 125, "Successful $$$ strategies")  ## Still have euro-symbol issues
    draw.text(328, 147, "for getting junior into the")
    draw.text(328, 169, "best business school")

    # ... and now drawing the text 
    #
    draw(full_slice)

    # Add the accent images on top
    #
    graphics_slice = new_blank_png(595, 182)
    
    left_image = Image(filename = IMAGE_PATH + "smartphone.png")
    left_image = resize_to_width(left_image, 299)

    right_image = Image(filename = IMAGE_PATH + "building.png")
    right_image = resize_to_width(right_image, 298)

    graphics_slice.composite(left_image, 0, 0)
    graphics_slice.composite(right_image, 299, 0)
    opacity_mask = new_blank_png(595, left_image.height, color=Color('rgb(75,75,75)'))
    graphics_slice.composite_channel(channel='all_channels', image=opacity_mask, 
        operator='copy_opacity')

    full_slice.composite_channel(channel='all_channels', image=graphics_slice, 
        operator='over', top=0, left=0)
 
    # Done.
    #
    return full_slice
Пример #8
0
    def draw_box(self, progress_tracker=None):
        if not self.check_paper_layout():
            return None

        tuckbox_dimensions = ['width', 'height', 'depth']
        paper_dimensions = ['width', 'height']
        if ((not all(dimension in self.tuckbox for dimension in tuckbox_dimensions)) or
            (not all(dimension in self.paper for dimension in paper_dimensions))):
            return None

        # How much white space on the sides
        margin_height = (self.paper['height'] - self.pattern_height()) / 2
        margin_width = (self.paper['width'] - self.pattern_width()) / 2

        # Main box draw
        draw = Drawing()
        draw.scale(POINT_PER_MM, POINT_PER_MM)
        draw.stroke_color = Color('black')
        draw.stroke_width = RESOLUTION / (200 * POINT_PER_MM)
        draw.fill_opacity = 0
        draw.translate(margin_width,
                       margin_height + self.lip_size() + self.tuckbox['depth'])
        draw.push()

        # Finger holds draw
        finger_draw = Drawing(draw)
        finger_draw.fill_opacity = 1
        finger_draw.fill_color = Color('white')
        finger_draw.push()

        # Dashed draw
        dashed_draw = Drawing(draw)
        dash_array = [min(self.tuckbox['depth'], self.tuckbox['width'],
                          self.tuckbox['height'])/13] * 2
        dashed_draw.stroke_color = Color('rgb(100,100,100)')
        dashed_draw.fill_opacity = 0
        dashed_draw.stroke_width = RESOLUTION / (300 * POINT_PER_MM)
        dashed_draw.stroke_dash_array = dash_array
        dashed_draw.stroke_dash_offset = 1

        # Folding guides draw
        folding_guides_draw = Drawing()
        folding_guides_draw.scale(POINT_PER_MM, POINT_PER_MM)
        folding_guides_draw.stroke_color = Color('black')
        folding_guides_draw.stroke_width = RESOLUTION / (200 * POINT_PER_MM)

        back_draw = Drawing(draw)
        back_dashed_draw = Drawing(dashed_draw)
        back_folding_guides_draw = Drawing(folding_guides_draw)

        if progress_tracker is not None:
            progress_tracker(5)

        two_openings = 'two_openings' in self.options and self.options['two_openings']
        two_pages = 'two_pages' in self.options and self.options['two_pages']

        dash_array = [min(self.tuckbox['depth'], self.tuckbox['width'],
                          self.tuckbox['height'])/13] * 2

        #
        # Draw the box (or the first page)
        #
        self.draw_front(draw, dashed_draw, two_openings)

        if two_pages:
            offset_left_to_back = self.tuckbox['depth']
        else:
            offset_left_to_back = self.tuckbox['depth']*2 + self.tuckbox['width']

        self.draw_back(offset_left_to_back, back_draw, back_dashed_draw, finger_draw, two_openings)

        if two_pages:
            back_draw.polyline([(self.tuckbox['depth'], 0),
                           (self.tuckbox['depth'] * 0.2, 0),
                           (self.tuckbox['depth'] * 0.2, self.tuckbox['height']),
                           (self.tuckbox['depth'], self.tuckbox['height'])])
            draw.line((self.tuckbox['depth']*2 + self.tuckbox['width'], 0),
                      (self.tuckbox['depth']*2 + self.tuckbox['width'], self.tuckbox['height']))

        if progress_tracker is not None:
            progress_tracker(10)

        # Create the image
        image = Image(width=math.ceil(self.paper['width'] * POINT_PER_MM),
                      height=math.ceil(self.paper['height'] * POINT_PER_MM),
                      background=Color('white'))
        image.resolution = RESOLUTION
        image.unit = 'pixelsperinch'

        if two_pages:
            image2 = Image(width=math.ceil(self.paper['width'] * POINT_PER_MM),
                        height=math.ceil(self.paper['height'] * POINT_PER_MM),
                        background=Color('white'))
            image2.resolution = RESOLUTION
            image2.unit = 'pixelsperinch'
        else:
            image2 = image

        # Draw the faces
        self.draw_faces(image, progress_tracker, with_back = not two_pages)
        if two_pages:
            self.draw_faces(image2, progress_tracker, only_back=True)

        # Draw the lip(s)
        lip = self.draw_lip(top=True)
        if lip is not None:
            image.composite(lip,
                            math.floor((margin_width + self.tuckbox['depth']) * POINT_PER_MM),
                            math.floor((margin_height) * POINT_PER_MM))

        if two_openings:
            lip = self.draw_lip(bottom=True)
            if lip is not None:
                image.composite(lip,
                                math.floor((margin_width + self.tuckbox['depth']) * POINT_PER_MM),
                                math.floor((margin_height + self.tuckbox['depth']*2 + self.lip_size() + self.tuckbox['height']) * POINT_PER_MM))

        if progress_tracker is not None:
            progress_tracker(80)

        # Draw all the lines over
        draw.draw(image)
        back_draw.draw(image2)

        finger_draw.draw(image2)
        self.draw_watermark(image)
        if two_pages:
            self.draw_watermark(image2)

        if progress_tracker is not None:
            progress_tracker(90)

        if "folds_dashed" in self.options and self.options["folds_dashed"]:
            dashed_draw.draw(image)
            back_dashed_draw.draw(image2)

        if "folding_guides" in self.options and self.options["folding_guides"]:
            front_vertical_folds = [margin_width + self.tuckbox['depth'],
                              margin_width +
                              self.tuckbox['depth'] + self.tuckbox['width']]
            if not two_pages:
                front_vertical_folds.extend([margin_width +
                                       self.tuckbox['depth']*2 + self.tuckbox['width'],
                                       margin_width + self.tuckbox['depth']*2 + self.tuckbox['width']*2])

            back_vertical_folds = [margin_width + self.tuckbox['depth'],
                                  margin_width +
                                  self.tuckbox['depth'] + self.tuckbox['width']]

            front_horizontal_folds = [margin_height + self.lip_size(),
                                margin_height + self.lip_size() +
                                self.tuckbox['depth'],
                                margin_height + self.lip_size() +
                                self.tuckbox['depth'] + self.tuckbox['height']]

            if two_openings:
                front_horizontal_folds.append(margin_height + self.lip_size() +
                                        self.tuckbox['depth'] * 2 + self.tuckbox['height'])
                back_horizontal_folds = []
            else:
                back_horizontal_folds = [margin_height + self.lip_size() +
                                        self.tuckbox['depth'] + self.tuckbox['height']]

            self.draw_folds(folding_guides_draw, front_vertical_folds, front_horizontal_folds, margin_height, margin_width)
            self.draw_folds(back_folding_guides_draw, back_vertical_folds, back_horizontal_folds, margin_height, margin_width)

            folding_guides_draw.draw(image)
            back_folding_guides_draw.draw(image2)

        if progress_tracker is not None:
            progress_tracker(100)

        if not two_pages:
            image2 = None

        return image, image2
Пример #9
0
# Prepare a drawing-context.
draw = Drawing()
evilColor = Color("#FF00FF")
extraColor = Color("#FF8000")
draw.stroke_color = evilColor
draw.stroke_width = 4 * scale
draw.fill_opacity = 0

# Draw empty frames around all of the rejected boxes.
for i in range(0,len(rejectedBoxes)):
	boxTop = rejectedBoxes[i]['boxTop']
	boxBottom= rejectedBoxes[i]['boxBottom']
	boxLeft = rejectedBoxes[i]['boxLeft']
	boxRight = rejectedBoxes[i]['boxRight']
	draw.line((boxLeft,boxTop), (boxRight,boxTop))
	draw.line((boxLeft,boxBottom), (boxRight,boxBottom))
	draw.line((boxRight,boxTop), (boxRight,boxBottom))
	draw.line((boxLeft,boxTop), (boxLeft,boxBottom))

# Loop on lines on the selected page.  
row = 0
boxIndex = 0
draw.stroke_color = extraColor
for row in range(0, len(lines)):
	if boxIndex >= len(boxes):
		if boxIndex < 1:
			top = 0
		else:
			#print 'Out of boxes in page, on row', row
			top = boxes[boxIndex-1]['boxBottom']