ishihara

package
v0.0.0-...-473980d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 25, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cli.Cmd[ishiharaArgs]{
	Name:        "ishihara",
	Usage:       "ishihara [PRIMARY COLORS] [SECONDARY COLORS] [MASK IMAGE PATH] [OUTPUT IMAGE PATH]",
	Description: "create an ishihara image using the given color pallets and mask image",
	Examples: []cli.Example{
		{
			Description: "create a red green colorblind test image",
			Args:        []string{"3a6a2f,76cd63", "a32222,db5f5f", "mask.png", "red_green.png"},
		},
	},
	ParseArgs: func(args []string) (ishiharaArgs, error) {
		if len(args) != 4 {
			return ishiharaArgs{}, errors.New("expected exactly 4 aguments")
		}

		primary := strings.Split(args[0], ",")
		primaryColors := []color.RGBA{}
		for _, hex := range primary {
			color, err := parseHex(hex)
			if err != nil {
				return ishiharaArgs{}, fmt.Errorf("failed to parse hex color '%s' %w", hex, err)
			}
			primaryColors = append(primaryColors, color)
		}

		secondary := strings.Split(args[1], ",")
		secondaryColors := []color.RGBA{}
		for _, hex := range secondary {
			color, err := parseHex(hex)
			if err != nil {
				return ishiharaArgs{}, fmt.Errorf("failed to parse hex color '%s' %w", hex, err)
			}
			secondaryColors = append(secondaryColors, color)
		}

		if !strings.HasSuffix(args[3], ".png") {
			return ishiharaArgs{}, errors.New("png is the only supported output image format")
		}

		return ishiharaArgs{
			primaryColors:   primaryColors,
			secondaryColors: secondaryColors,
			maskImagePath:   args[2],
			outputImagePath: args[3],
		}, nil
	},
	Fn: func(args ishiharaArgs) error {
		maskFile, err := os.Open(args.maskImagePath)
		if err != nil {
			return fmt.Errorf("failed to read mask image: %v", err)
		}
		defer maskFile.Close()

		mask, _, err := image.Decode(maskFile)
		if err != nil {
			return fmt.Errorf("failed to decode mask image: %v", err)
		}

		imgData := newIshihara(mask)
		img := imgData.render(args.primaryColors, args.secondaryColors)

		outFile, err := os.Create(args.outputImagePath)
		if err != nil {
			return fmt.Errorf("failed to create output image file: %v", err)
		}
		defer outFile.Close()

		return png.Encode(outFile, img)
	},
}

Cmd is the ishihara command used to generate ishihara images

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL