Draw Capatcha Code to Image
960072
private function drawCapatchaImageText()
	{
		
		#	Create Image Text
	
		# here we will first create background text, then front text
		# we will set x- position
		# initial front text position 'initial_x'
		# current position 'current_x'
		
		$this->_front_text['initial_x'] = $this->_front_text['x'] = rand( 10, 25 );
		
		# Background Text
		# X, Y positions
		
		$this->_background_text['x'] = $this->_front_text['x'] / 2;
		$this->_background_text['y'] = ( $this->_calculated_text_box['dimensions']['height'] ) + ( $this->_calculated_text_box['additional_height'] / 2 );

		// Developing::preview( $this->_calculated_text_box['additional_height'], $this->_image_info['height'] - $this->_calculated_text_box['dimensions']['height'] );
		
		$characters = str_split( $this->_code, 1 );
		
		# Generating background text By Drawing letter by letter
		foreach( $characters as $char )
		{
			# character rotation angle
			$rotation_angle = rand( 0 - $this->_rotation_angle, $this->_rotation_angle );

			# get color rgb values
			$rgb = $this->getRGBFromRange(
				$this->_background_text['color'][0],
				$this->_background_text['color'][1],
				$this->_background_text['color'][2],
				$this->_background_text['color']['range']
				);
			
			$character_color = imagecolorallocatealpha(
				$this->_image_resource,
				$rgb[0],
				$rgb[1],
				$rgb[2],
				$this->_background_text['color'][3]
				);

			# check to add the blocks seperation distance
			if( $char === ' ' )
				$this->_background_text['x'] += $this->_blocks_seperation;
			
			# Draw Character to the image
			imagettftext(
				$this->_image_resource,					# Image resource
				$this->_background_text['size'],		# Font Size
				$rotation_angle,						# Text Angle
				$this->_background_text['x'],			# X Position
				$this->_background_text['y'],			# Y Position
				$character_color,						# Color
				$this->_background_text['font'],		# Font
				$char 									# Text
				);
			
			# move x to the next position			
			// $this->_background_text['x'] += $this->getTextBoxDimensions(
			// 	$this->_background_text['size'],
			// 	$rotation_angle,
			// 	$this->_background_text['font'],
			// 	$char
			// 	)['width'];

			$box_dimension = $this->getTextBoxDimensions(
				$this->_background_text['size'],
				$rotation_angle,
				$this->_background_text['font'],
				$char
				);

			$this->_background_text['x'] += $box_dimension['width'];
			

			# Method End
		}
		
		
		# space between characters equal 1/4  average character width
		$space_between_chars = $this->_calculated_text_box['char_width'] / 4;

		# final character index
		$final_character_index = $this->_code_length - 1;
		
		
		# Front Text
		foreach( $characters as $index => $char )
		{
			
			# the same as background text
			
			$rotation_angle = rand( 0 - $this->_rotation_angle, $this->_rotation_angle );
			
			# get color rgb values
			$rgb = $this->getRGBFromRange(
				$this->_front_text['color'][0],
				$this->_front_text['color'][1],
				$this->_front_text['color'][2],
				$this->_front_text['color']['range']
				);

			$character_color = imagecolorallocatealpha(
				$this->_image_resource,
				$rgb[0],
				$rgb[1],
				$rgb[2],
				$this->_front_text['color'][3]
				);

			# Calculate Character Dimensions
			$character_box = $this->getTextBoxDimensions(
				$this->_front_text['size'],
				$rotation_angle,
				$this->_front_text['font'],
				$char
				);

			# # calculate y position
			// $this->_front_text['y'] = ( $character_box['height'] - abs( $character_box['points'][1] ) ) + ( ( $this->_image_info['height'] - $character_box['height'] ) / 2 );
			// Developing::preview( 'index' . $index . ': ' . ( $character_box['height'] - abs( $character_box['points'][1] ) ), 'index' . $index . ': ' . $character_box['points'][5] );
			// exit;
			
			$this->_front_text['y'] = abs( $character_box['height'] ) + ( ( $this->_image_info['height'] - $character_box['height'] ) / 2 ) ; 
			
			# check to add the blocks seperation distance
			if( $char === ' ' )
				$this->_front_text['x'] += $this->_blocks_seperation;
			
			
			# Draw Character To Image
			imagettftext(
						 $this->_image_resource,
						 $this->_front_text['size'],
						 $rotation_angle,
						 $this->_front_text['x'],
						 $this->_front_text['y'],
						 $character_color,
						 $this->_front_text['font'],
						 $char
						);
			
			$this->_front_text['x'] += $character_box['width'];
			
			$this->_front_text['x'] += ( $index !== $final_character_index ) ? $space_between_chars : null;
		
		}

		# Method End	
	}
458924
function (opt) {
    var cap = new Captcha(opt);
    cap.use(drawBackground);
    cap.use(drawLines);
    cap.use(drawText);
    cap.use(drawLines);
    return cap;
  }
36693
def generate(str, alg):
    """"""
    img = Image.new(IMAGE_MODE, IMAGE_SIZE, BACKGROUND_COLOR)
    hashcode = hash_input(str, alg)
    pixelmap = setup_pixelmap(hashcode)
    draw_image(pixelmap, img)
    return img
208286
function (symbol, symbolSize, style, canvas) {
        var path = makePath(symbol, symbolSize, style);

        var margin = spriteUtil.getMarginByStyle(style);

        return {
            image: makeSprite(path.__size, canvas, function (ctx) {
                path.brush(ctx);
            }),
            margin: margin
        };
    }
285618
function(src) {
	var canvas = document.createElement('canvas'),
		ctx = canvas.getContext('2d'),
		imgObj = new Image();
	
	imgObj.src = src;
	canvas.width = imgObj.width;
	canvas.height = imgObj.height; 
	
	ctx.drawImage(imgObj, 0, 0); 
	var imgPixels = ctx.getImageData(0, 0, canvas.width, canvas.height);

	for(var y = 0; y < imgPixels.height; y++){
		for(var x = 0; x < imgPixels.width; x++){
			var i = (y * 4) * imgPixels.width + x * 4;
			var avg = (imgPixels.data[i] + imgPixels.data[i + 1] + imgPixels.data[i + 2]) / 3;
			imgPixels.data[i] = avg; 
			imgPixels.data[i + 1] = avg; 
			imgPixels.data[i + 2] = avg;
		}
	}
	
	ctx.putImageData(imgPixels, 0, 0, 0, 0, imgPixels.width, imgPixels.height);
	return canvas.toDataURL();
}
664128
def render_to_png(self, filename=None, dpi=72, **kwargs):
        """"""
        import cairosvg
        return cairosvg.svg2png(
            bytestring=self.render(**kwargs), write_to=filename, dpi=dpi
        )
1287546
def Draw(self, dc):
        '''  '''
        self.hot_map = []
        dc.BeginDrawing()
        brush = wx.Brush( self.BackgroundColour  )
        dc.SetBackground( brush )
        dc.Clear()
        if self.model:
            self.max_depth_seen = 0
            font = self.FontForLabels(dc)
            dc.SetFont(font)
            self._em_size_ = dc.GetFullTextExtent( 'm', font )[0]
            w, h = dc.GetSize()
            self.DrawBox( dc, self.model, 0,0,w,h, hot_map = self.hot_map )
        dc.EndDrawing()
71674
function renderImageToCanvas(img, canvas, options) {
		var iw = img.naturalWidth, ih = img.naturalHeight;
		var width = options.width, height = options.height;
		var x = options.x || 0, y = options.y || 0;
		var ctx = canvas.getContext('2d');
		if (detectSubsampling(img)) {
			iw /= 2;
			ih /= 2;
		}
		var d = 1024; // size of tiling canvas
		var tmpCanvas = document.createElement('canvas');
		tmpCanvas.width = tmpCanvas.height = d;
		var tmpCtx = tmpCanvas.getContext('2d');
		var vertSquashRatio = detectVerticalSquash(img, iw, ih);
		var sy = 0;
		while (sy < ih) {
			var sh = sy + d > ih ? ih - sy : d;
			var sx = 0;
			while (sx < iw) {
				var sw = sx + d > iw ? iw - sx : d;
				tmpCtx.clearRect(0, 0, d, d);
				tmpCtx.drawImage(img, -sx, -sy);
				var dx = (sx * width / iw + x) << 0;
				var dw = Math.ceil(sw * width / iw);
				var dy = (sy * height / ih / vertSquashRatio + y) << 0;
				var dh = Math.ceil(sh * height / ih / vertSquashRatio);
				ctx.drawImage(tmpCanvas, 0, 0, sw, sh, dx, dy, dw, dh);
				sx += d;
			}
			sy += d;
		}
		tmpCanvas = tmpCtx = null;
	}
806848
def draw(self):
        """"""
        if not self.visible:
            return

        self.window.blit(self.textImage, self.loc)
216303
def draw_line(self, img, pixmapper, pt1, pt2, colour, linewidth):
        ''''''
        pix1 = pixmapper(pt1)
        pix2 = pixmapper(pt2)
        (width, height) = image_shape(img)
        (ret, pix1, pix2) = cv2.clipLine((0, 0, width, height), pix1, pix2)
        if ret is False:
            if len(self._pix_points) == 0:
                self._pix_points.append(None)
            self._pix_points.append(None)
            return
        cv2.line(img, pix1, pix2, colour, linewidth)
        cv2.circle(img, pix2, linewidth*2, colour)
        if len(self._pix_points) == 0:
            self._pix_points.append(pix1)
        self._pix_points.append(pix2)
        if self.arrow:
            xdiff = pix2[0]-pix1[0]
            ydiff = pix2[1]-pix1[1]
            if (xdiff*xdiff + ydiff*ydiff) > 400: # the segment is longer than 20 pix
                SlipArrow(self.key, self.layer, (int(pix1[0]+xdiff/2.0), int(pix1[1]+ydiff/2.0)), self.colour,
                          self.linewidth, math.atan2(ydiff, xdiff)+math.pi/2.0).draw(img)
708416
def draw_image(pixelmap, img):
    ''''''
    for item in pixelmap:
        color = item[2]

        # Access the rectangle edges.
        pixelbox = (item[0][0], item[0][1], item[1][0], item[1][1])
        draw = ImageDraw.Draw(img)
        draw.rectangle(pixelbox, fill=color)
238507
def draw(self):
        """"""
        if sys.stdout.isatty():  # pragma: no cover
            from asciimatics.screen import Screen

            Screen.wrapper(self._do_draw)
        else:
            for line in self.canvas:
                print("".join(line))
174610
def create_captcha_image(self, chars, color, background):
        
        image = Image.new('RGB', (self._width, self._height), background)
        draw = Draw(image)

        def _draw_character(c):
            font = random.choice(self.truefonts)
            w, h = draw.textsize(c, font=font)

            dx = random.randint(0, 4)
            dy = random.randint(0, 6)
            im = Image.new('RGBA', (w + dx, h + dy))
            Draw(im).text((dx, dy), c, font=font, fill=color)

            # rotate
            im = im.crop(im.getbbox())
            im = im.rotate(random.uniform(-30, 30), Image.BILINEAR, expand=1)

            # warp
            dx = w * random.uniform(0.1, 0.3)
            dy = h * random.uniform(0.2, 0.3)
            x1 = int(random.uniform(-dx, dx))
            y1 = int(random.uniform(-dy, dy))
            x2 = int(random.uniform(-dx, dx))
            y2 = int(random.uniform(-dy, dy))
            w2 = w + abs(x1) + abs(x2)
            h2 = h + abs(y1) + abs(y2)
            data = (
                x1, y1,
                -x1, h2 - y2,
                w2 + x2, h2 + y2,
                w2 - x2, -y1,
            )
            im = im.resize((w2, h2))
            im = im.transform((w, h), Image.QUAD, data)
            return im

        images = []
        for c in chars:
            if random.random() > 0.5:
                images.append(_draw_character(" "))
            images.append(_draw_character(c))

        text_width = sum([im.size[0] for im in images])

        width = max(text_width, self._width)
        image = image.resize((width, self._height))

        average = int(text_width / len(chars))
        rand = int(0.25 * average)
        offset = int(average * 0.1)

        for im in images:
            w, h = im.size
            mask = im.convert('L').point(table)
            image.paste(im, (offset, int((self._height - h) / 2)), mask)
            offset = offset + w + random.randint(-rand, 0)

        if width > self._width:
            image = image.resize((self._width, self._height))

        return image
555398
def encode_images_as_png(images):
  """"""
  if tf.executing_eagerly():
    for image in images:
      yield tf.image.encode_png(image).numpy()
  else:
    (height, width, channels) = images[0].shape
    with tf.Graph().as_default():
      image_t = tf.placeholder(dtype=tf.uint8, shape=(height, width, channels))
      encoded_image_t = tf.image.encode_png(image_t)
      with tf.Session() as sess:
        for image in images:
          enc_string = sess.run(encoded_image_t, feed_dict={image_t: image})
          yield enc_string
198671
def drawQuad(page, quad, color=None, fill=None, dashes=None,
             width=1, roundCap=False, morph=None, overlay=True):
    
    img = page.newShape()
    Q = img.drawQuad(Quad(quad))
    img.finish(color=color, fill=fill, dashes=dashes, width=width,
                   roundCap=roundCap, morph=morph)
    img.commit(overlay)

    return Q
868471
def render(self, code):
        
        if self._callbacks['initialize'] is not None:
            self._callbacks['initialize'](code)
        ypos = 1.0
        for cc, line in enumerate(code):
            """
            Pack line to list give better gfx result, otherwise in can
            result in aliasing gaps
            '11010111' -> [2, -1, 1, -1, 3]
            """
            line += ' '
            c = 1
            mlist = []
            for i in range(0, len(line) - 1):
                if line[i] == line[i+1]:
                    c += 1
                else:
                    if line[i] == "1":
                        mlist.append(c)
                    else:
                        mlist.append(-c)
                    c = 1
            # Left quiet zone is x startposition
            xpos = self.quiet_zone
            bxs = xpos  # x start of barcode
            for mod in mlist:
                if mod < 1:
                    color = self.background
                else:
                    color = self.foreground
                # remove painting for background colored tiles?
                self._callbacks['paint_module'](
                    xpos, ypos, self.module_width * abs(mod), color
                )
                xpos += self.module_width * abs(mod)
            bxe = xpos
            # Add right quiet zone to every line, except last line,
            # quiet zone already provided with background,
            # should it be removed complety?
            if (cc + 1) != len(code):
                self._callbacks['paint_module'](
                    xpos, ypos, self.quiet_zone, self.background
                )
            ypos += self.module_height
        if self.text and self._callbacks['paint_text'] is not None:
            ypos += self.text_distance
            if self.center_text:
                # better center position for text
                xpos = bxs + ((bxe - bxs) / 2.0)
            else:
                xpos = bxs
            self._callbacks['paint_text'](xpos, ypos)
        return self._callbacks['finish']()
669211
def draw_rectangle(x, y, width, height, attr = {})
            load!

            stroke_color  = attr.fetch(:stroke_color, DEFAULT_STROKE_COLOR)
            fill_color    = attr.fetch(:fill_color, DEFAULT_FILL_COLOR)
            line_cap      = attr.fetch(:line_cap, DEFAULT_LINECAP)
            line_join     = attr.fetch(:line_join, DEFAULT_LINEJOIN)
            line_width    = attr.fetch(:line_width, DEFAULT_LINEWIDTH)
            dash_pattern  = attr.fetch(:dash, DEFAULT_DASHPATTERN)

            stroke        = attr[:stroke].nil? ? true : attr[:stroke]
            fill          = attr[:fill].nil? ? false : attr[:fill]

            stroke = true if fill == false and stroke == false

            set_fill_color(fill_color) if fill
            set_stroke_color(stroke_color) if stroke
            set_line_width(line_width)
            set_line_cap(line_cap)
            set_line_join(line_join)
            set_dash_pattern(dash_pattern)

            if @canvas.gs.text_state.is_in_text_object?
                @instructions << PDF::Instruction.new('ET').render(@canvas)
            end

            @instructions << PDF::Instruction.new('re', x,y,width,height).render(@canvas)

            @instructions << (i =
                if stroke and not fill
                    PDF::Instruction.new('S')
                elsif fill and not stroke
                    PDF::Instruction.new('f')
                elsif fill and stroke
                    PDF::Instruction.new('B')
                end
            )

            i.render(@canvas)

            self
        end