<commit_before>package main

import (
	"image"

	"github.com/llgcode/draw2d"
	"github.com/llgcode/draw2d/draw2dimg"
)

func fontFileName(fontData draw2d.FontData) string {
	return fontData.Name + ".ttf"
}

func drawDigitsWithFont(digit string, fontName string, fontSize float64) image.Image {
	canvas := image.NewRGBA(image.Rect(0, 0, 28, 28))
	gc := draw2dimg.NewGraphicContext(canvas)

	gc.DrawImage(image.White)    // Background color
	gc.SetFillColor(image.Black) // Text color

	gc.SetFontData(draw2d.FontData{Name: fontName})
	gc.SetFontSize(fontSize)

	left, top, right, bottom := gc.GetStringBounds(digit)
	height := bottom - top
	width := right - left

	center := 28.0 / 2
	gc.FillStringAt(digit, center-width/2, center+height/2)

	return canvas
}

func main() {
	draw2d.SetFontFolder("./fonts/")
	draw2d.SetFontNamer(fontFileName)

	digit := drawDigitsWithFont("8", "OpenSans-Regular", 14)
	draw2dimg.SaveToPngFile("digits.png", digit)
}<commit_msg>Create images in loop from given text<commit_after>package main

import (
	"fmt"
	"image"
	"os"
	"path"

	"github.com/llgcode/draw2d"
	"github.com/llgcode/draw2d/draw2dimg"
)

var outDir = "out"

func fontFileName(fontData draw2d.FontData) string {
	return fontData.Name + ".ttf"
}

func drawDigitsWithFont(digit string, fontName string, fontSize float64) image.Image {
	canvas := image.NewRGBA(image.Rect(0, 0, 28, 28))
	gc := draw2dimg.NewGraphicContext(canvas)

	gc.DrawImage(image.White)    // Background color
	gc.SetFillColor(image.Black) // Text color

	gc.SetFontData(draw2d.FontData{Name: fontName})
	gc.SetFontSize(fontSize)

	left, top, right, bottom := gc.GetStringBounds(digit)
	height := bottom - top
	width := right - left

	center := 28.0 / 2
	gc.FillStringAt(digit, center-width/2, center+height/2)

	return canvas
}

func main() {
	draw2d.SetFontFolder("./fonts/")
	draw2d.SetFontNamer(fontFileName)

	os.RemoveAll(outDir)
	if err := os.Mkdir(outDir, 0764); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	text := `123456789 +=\|/[]*-$#@`
	for i, c := range text {
		digit := drawDigitsWithFont(string(c), "OpenSans-Regular", 14)

		fileName := fmt.Sprintf("char-%06d.png", i)
		err := draw2dimg.SaveToPngFile(path.Join(outDir, fileName), digit)
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
	}
}
{'fraction_non_alphanumeric': 0.1487964989059081, 'fraction_numerical': 0.02975929978118162, 'mean_word_length': 4.442857142857143, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5137642', 'n_tokens_mistral': 950, 'n_tokens_neox': 880, 'n_words': 170}