Added --color-bg flag
This commit is contained in:
parent
50b6b0081f
commit
202179dd2d
|
|
@ -105,9 +105,9 @@ func pathIsGif(gifPath, urlImgName string, pathIsURl bool, urlImgBytes []byte, l
|
||||||
|
|
||||||
var asciiCharSet [][]imgManip.AsciiChar
|
var asciiCharSet [][]imgManip.AsciiChar
|
||||||
if braille {
|
if braille {
|
||||||
asciiCharSet = imgManip.ConvertToBrailleChars(imgSet, negative, colored, fontColor, threshold)
|
asciiCharSet = imgManip.ConvertToBrailleChars(imgSet, negative, colored, colorBg, fontColor, threshold)
|
||||||
} else {
|
} else {
|
||||||
asciiCharSet = imgManip.ConvertToAsciiChars(imgSet, negative, colored, complex, customMap, fontColor)
|
asciiCharSet = imgManip.ConvertToAsciiChars(imgSet, negative, colored, complex, colorBg, customMap, fontColor)
|
||||||
}
|
}
|
||||||
gifFramesSlice[i].asciiCharSet = asciiCharSet
|
gifFramesSlice[i].asciiCharSet = asciiCharSet
|
||||||
gifFramesSlice[i].delay = originalGif.Delay[i]
|
gifFramesSlice[i].delay = originalGif.Delay[i]
|
||||||
|
|
|
||||||
|
|
@ -51,9 +51,9 @@ func pathIsImage(imagePath, urlImgName string, pathIsURl bool, urlImgBytes []byt
|
||||||
var asciiSet [][]imgManip.AsciiChar
|
var asciiSet [][]imgManip.AsciiChar
|
||||||
|
|
||||||
if braille {
|
if braille {
|
||||||
asciiSet = imgManip.ConvertToBrailleChars(imgSet, negative, colored, fontColor, threshold)
|
asciiSet = imgManip.ConvertToBrailleChars(imgSet, negative, colored, colorBg, fontColor, threshold)
|
||||||
} else {
|
} else {
|
||||||
asciiSet = imgManip.ConvertToAsciiChars(imgSet, negative, colored, complex, customMap, fontColor)
|
asciiSet = imgManip.ConvertToAsciiChars(imgSet, negative, colored, complex, colorBg, customMap, fontColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save ascii art as .png image before printing it, if --save-img flag is passed
|
// Save ascii art as .png image before printing it, if --save-img flag is passed
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ func DefaultFlags() Flags {
|
||||||
SaveGifPath: "",
|
SaveGifPath: "",
|
||||||
Negative: false,
|
Negative: false,
|
||||||
Colored: false,
|
Colored: false,
|
||||||
|
CharBackgroundColor: false,
|
||||||
Grayscale: false,
|
Grayscale: false,
|
||||||
CustomMap: "",
|
CustomMap: "",
|
||||||
FlipX: false,
|
FlipX: false,
|
||||||
|
|
@ -82,6 +83,7 @@ func Convert(filePath string, flags Flags) (string, error) {
|
||||||
saveGifPath = flags.SaveGifPath
|
saveGifPath = flags.SaveGifPath
|
||||||
negative = flags.Negative
|
negative = flags.Negative
|
||||||
colored = flags.Colored
|
colored = flags.Colored
|
||||||
|
colorBg = flags.CharBackgroundColor
|
||||||
grayscale = flags.Grayscale
|
grayscale = flags.Grayscale
|
||||||
customMap = flags.CustomMap
|
customMap = flags.CustomMap
|
||||||
flipX = flags.FlipX
|
flipX = flags.FlipX
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,10 @@ type Flags struct {
|
||||||
// This overrides Flags.Grayscale and Flags.FontColor
|
// This overrides Flags.Grayscale and Flags.FontColor
|
||||||
Colored bool
|
Colored bool
|
||||||
|
|
||||||
|
// If Flags.Colored, Flags.Grayscale or Flags.FontColor is set, use that color
|
||||||
|
// on each character's background in the terminal
|
||||||
|
CharBackgroundColor bool
|
||||||
|
|
||||||
// Keep grayscale colors from the original image. This uses the True color
|
// Keep grayscale colors from the original image. This uses the True color
|
||||||
// codes for the terminal and will work on saved .png and .gif files as well
|
// codes for the terminal and will work on saved .png and .gif files as well
|
||||||
// This overrides Flags.FontColor
|
// This overrides Flags.FontColor
|
||||||
|
|
@ -103,6 +107,7 @@ var (
|
||||||
grayscale bool
|
grayscale bool
|
||||||
negative bool
|
negative bool
|
||||||
colored bool
|
colored bool
|
||||||
|
colorBg bool
|
||||||
customMap string
|
customMap string
|
||||||
flipX bool
|
flipX bool
|
||||||
flipY bool
|
flipY bool
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ var (
|
||||||
negative bool
|
negative bool
|
||||||
formatsTrue bool
|
formatsTrue bool
|
||||||
colored bool
|
colored bool
|
||||||
|
colorBg bool
|
||||||
grayscale bool
|
grayscale bool
|
||||||
customMap string
|
customMap string
|
||||||
flipX bool
|
flipX bool
|
||||||
|
|
@ -55,7 +56,7 @@ var (
|
||||||
rootCmd = &cobra.Command{
|
rootCmd = &cobra.Command{
|
||||||
Use: "ascii-image-converter [image paths/urls]",
|
Use: "ascii-image-converter [image paths/urls]",
|
||||||
Short: "Converts images and gifs into ascii art",
|
Short: "Converts images and gifs into ascii art",
|
||||||
Version: "1.7.1",
|
Version: "1.8.0",
|
||||||
Long: "This tool converts images into ascii art and prints them on the terminal.\nFurther configuration can be managed with flags.",
|
Long: "This tool converts images into ascii art and prints them on the terminal.\nFurther configuration can be managed with flags.",
|
||||||
|
|
||||||
// Not RunE since help text is getting larger and seeing it for every error impacts user experience
|
// Not RunE since help text is getting larger and seeing it for every error impacts user experience
|
||||||
|
|
@ -75,6 +76,7 @@ var (
|
||||||
SaveGifPath: saveGifPath,
|
SaveGifPath: saveGifPath,
|
||||||
Negative: negative,
|
Negative: negative,
|
||||||
Colored: colored,
|
Colored: colored,
|
||||||
|
CharBackgroundColor: colorBg,
|
||||||
Grayscale: grayscale,
|
Grayscale: grayscale,
|
||||||
CustomMap: customMap,
|
CustomMap: customMap,
|
||||||
FlipX: flipX,
|
FlipX: flipX,
|
||||||
|
|
@ -124,6 +126,7 @@ func init() {
|
||||||
|
|
||||||
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.ascii-image-converter.yaml)")
|
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.ascii-image-converter.yaml)")
|
||||||
rootCmd.PersistentFlags().BoolVarP(&colored, "color", "C", false, "Display ascii art with original colors\n(Inverts with --negative flag)\n(Overrides --grayscale and --font-color flags)\n")
|
rootCmd.PersistentFlags().BoolVarP(&colored, "color", "C", false, "Display ascii art with original colors\n(Inverts with --negative flag)\n(Overrides --grayscale and --font-color flags)\n")
|
||||||
|
rootCmd.PersistentFlags().BoolVar(&colorBg, "color-bg", false, "If some color flag is passed, use that color\non character background instead of foreground\n(Inverts with --negative flag)\n(Doesn't work for --save-img or --save-gif)\n")
|
||||||
rootCmd.PersistentFlags().IntSliceVarP(&dimensions, "dimensions", "d", nil, "Set width and height for ascii art in CHARACTER length\ne.g. -d 60,30 (defaults to terminal height)\n(Overrides --width and --height flags)\n")
|
rootCmd.PersistentFlags().IntSliceVarP(&dimensions, "dimensions", "d", nil, "Set width and height for ascii art in CHARACTER length\ne.g. -d 60,30 (defaults to terminal height)\n(Overrides --width and --height flags)\n")
|
||||||
rootCmd.PersistentFlags().IntVarP(&width, "width", "W", 0, "Set width for ascii art in CHARACTER length\nHeight is kept to aspect ratio\ne.g. -W 60\n")
|
rootCmd.PersistentFlags().IntVarP(&width, "width", "W", 0, "Set width for ascii art in CHARACTER length\nHeight is kept to aspect ratio\ne.g. -W 60\n")
|
||||||
rootCmd.PersistentFlags().IntVarP(&height, "height", "H", 0, "Set height for ascii art in CHARACTER length\nWidth is kept to aspect ratio\ne.g. -H 60\n")
|
rootCmd.PersistentFlags().IntVarP(&height, "height", "H", 0, "Set height for ascii art in CHARACTER length\nWidth is kept to aspect ratio\ne.g. -H 60\n")
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ to a 2D image_conversions.AsciiChar slice
|
||||||
If complex parameter is true, values are compared to 70 levels of color density in ASCII characters.
|
If complex parameter is true, values are compared to 70 levels of color density in ASCII characters.
|
||||||
Otherwise, values are compared to 10 levels of color density in ASCII characters.
|
Otherwise, values are compared to 10 levels of color density in ASCII characters.
|
||||||
*/
|
*/
|
||||||
func ConvertToAsciiChars(imgSet [][]AsciiPixel, negative, colored, complex bool, customMap string, fontColor [3]int) [][]AsciiChar {
|
func ConvertToAsciiChars(imgSet [][]AsciiPixel, negative, colored, complex, colorBg bool, customMap string, fontColor [3]int) [][]AsciiChar {
|
||||||
|
|
||||||
height := len(imgSet)
|
height := len(imgSet)
|
||||||
width := len(imgSet[0])
|
width := len(imgSet[0])
|
||||||
|
|
@ -134,7 +134,12 @@ func ConvertToAsciiChars(imgSet [][]AsciiPixel, negative, colored, complex bool,
|
||||||
|
|
||||||
var char AsciiChar
|
var char AsciiChar
|
||||||
|
|
||||||
char.OriginalColor = color.Sprintf("<fg="+rStr+","+gStr+","+bStr+">%v</>", chosenTable[tempInt])
|
char.Simple = chosenTable[tempInt]
|
||||||
|
if colorBg {
|
||||||
|
char.OriginalColor = color.Sprintf("<bg="+rStr+","+gStr+","+bStr+">%v</>", chosenTable[tempInt])
|
||||||
|
} else {
|
||||||
|
char.OriginalColor = color.Sprintf("<fg="+rStr+","+gStr+","+bStr+">%v</>", chosenTable[tempInt])
|
||||||
|
}
|
||||||
|
|
||||||
// If font color is not set, use a simple string. Otherwise, use True color
|
// If font color is not set, use a simple string. Otherwise, use True color
|
||||||
if fontColor != [3]int{255, 255, 255} {
|
if fontColor != [3]int{255, 255, 255} {
|
||||||
|
|
@ -142,11 +147,13 @@ func ConvertToAsciiChars(imgSet [][]AsciiPixel, negative, colored, complex bool,
|
||||||
fcG := strconv.Itoa(fontColor[1])
|
fcG := strconv.Itoa(fontColor[1])
|
||||||
fcB := strconv.Itoa(fontColor[2])
|
fcB := strconv.Itoa(fontColor[2])
|
||||||
|
|
||||||
char.SetColor = color.Sprintf("<fg="+fcR+","+fcG+","+fcB+">%v</>", chosenTable[tempInt])
|
if colorBg {
|
||||||
|
char.SetColor = color.Sprintf("<bg="+fcR+","+fcG+","+fcB+">%v</>", chosenTable[tempInt])
|
||||||
|
} else {
|
||||||
|
char.SetColor = color.Sprintf("<fg="+fcR+","+fcG+","+fcB+">%v</>", chosenTable[tempInt])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char.Simple = chosenTable[tempInt]
|
|
||||||
|
|
||||||
if colored {
|
if colored {
|
||||||
char.RgbValue = imgSet[i][j].rgbValue
|
char.RgbValue = imgSet[i][j].rgbValue
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -167,7 +174,7 @@ to a 2D image_conversions.AsciiChar slice
|
||||||
|
|
||||||
Unlike ConvertToAsciiChars(), this function calculates braille characters instead of ascii
|
Unlike ConvertToAsciiChars(), this function calculates braille characters instead of ascii
|
||||||
*/
|
*/
|
||||||
func ConvertToBrailleChars(imgSet [][]AsciiPixel, negative, colored bool, fontColor [3]int, threshold int) [][]AsciiChar {
|
func ConvertToBrailleChars(imgSet [][]AsciiPixel, negative, colored, colorBg bool, fontColor [3]int, threshold int) [][]AsciiChar {
|
||||||
|
|
||||||
BrailleThreshold = uint32(threshold)
|
BrailleThreshold = uint32(threshold)
|
||||||
|
|
||||||
|
|
@ -216,7 +223,11 @@ func ConvertToBrailleChars(imgSet [][]AsciiPixel, negative, colored bool, fontCo
|
||||||
var char AsciiChar
|
var char AsciiChar
|
||||||
|
|
||||||
char.Simple = brailleChar
|
char.Simple = brailleChar
|
||||||
char.OriginalColor = color.Sprintf("<fg="+rStr+","+gStr+","+bStr+">%v</>", brailleChar)
|
if colorBg {
|
||||||
|
char.OriginalColor = color.Sprintf("<bg="+rStr+","+gStr+","+bStr+">%v</>", brailleChar)
|
||||||
|
} else {
|
||||||
|
char.OriginalColor = color.Sprintf("<fg="+rStr+","+gStr+","+bStr+">%v</>", brailleChar)
|
||||||
|
}
|
||||||
|
|
||||||
// If font color is not set, use a simple string. Otherwise, use True color
|
// If font color is not set, use a simple string. Otherwise, use True color
|
||||||
if fontColor != [3]int{255, 255, 255} {
|
if fontColor != [3]int{255, 255, 255} {
|
||||||
|
|
@ -224,7 +235,11 @@ func ConvertToBrailleChars(imgSet [][]AsciiPixel, negative, colored bool, fontCo
|
||||||
fcG := strconv.Itoa(fontColor[1])
|
fcG := strconv.Itoa(fontColor[1])
|
||||||
fcB := strconv.Itoa(fontColor[2])
|
fcB := strconv.Itoa(fontColor[2])
|
||||||
|
|
||||||
char.SetColor = color.Sprintf("<fg="+fcR+","+fcG+","+fcB+">%v</>", brailleChar)
|
if colorBg {
|
||||||
|
char.SetColor = color.Sprintf("<bg="+fcR+","+fcG+","+fcB+">%v</>", brailleChar)
|
||||||
|
} else {
|
||||||
|
char.SetColor = color.Sprintf("<fg="+fcR+","+fcG+","+fcB+">%v</>", brailleChar)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if colored {
|
if colored {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
name: ascii-image-converter
|
name: ascii-image-converter
|
||||||
base: core18
|
base: core18
|
||||||
version: "1.7.1"
|
version: "1.8.0"
|
||||||
summary: Convert images and gifs into ascii art
|
summary: Convert images and gifs into ascii art
|
||||||
description: |
|
description: |
|
||||||
ascii-image-converter is a command-line tool that converts images into ascii art and prints
|
ascii-image-converter is a command-line tool that converts images into ascii art and prints
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue