TheZoraiz / ascii-image-converter

A cross-platform command-line tool to convert images into ascii art and print them on the console. Now supports braille art!
Apache License 2.0
2.05k stars 121 forks source link

panic: runtime error: index out of range [0] with length 0 #14

Closed lepapareil closed 2 years ago

lepapareil commented 2 years ago

Hi :)

Depending on which env i run it, it can result on:

$ ascii-image-converter ./my_image.png

panic: runtime error: index out of range [0] with length 0
goroutine 1 [running]:
github.com/TheZoraiz/ascii-image-converter/image_manipulation.ConvertToBrailleChars(0x0, 0x0, 0x0, 0x100, 0xff, 0xff, 0xff, 0x32, 0x0, 0x0, ...)
    /home/zozu/Stuff/Projects/ascii-image-converter/image_manipulation/ascii_conversions.go:180 +0xa6c
github.com/TheZoraiz/ascii-image-converter/aic_package.pathIsImage(0x7ffeae218883, 0xa, 0x0, 0x0, 0xc00000c300, 0x0, 0x0, 0x0, 0xc000010128, 0xc0000304f8, ...)
    /home/zozu/Stuff/Projects/ascii-image-converter/aic_package/convert_image.go:54 +0x2ee
github.com/TheZoraiz/ascii-image-converter/aic_package.Convert(0x7ffeae218883, 0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
    /home/zozu/Stuff/Projects/ascii-image-converter/aic_package/convert_root.go:157 +0x668
github.com/TheZoraiz/ascii-image-converter/cmd.glob..func1(0xd26560, 0xc0000a48c0, 0x1, 0x5)
    /home/zozu/Stuff/Projects/ascii-image-converter/cmd/root.go:97 +0x379
github.com/spf13/cobra.(*Command).execute(0xd26560, 0xc000020250, 0x5, 0x5, 0xd26560, 0xc000020250)
    /home/zozu/go/pkg/mod/github.com/spf13/cobra@v1.1.3/command.go:856 +0x2c2
github.com/spf13/cobra.(*Command).ExecuteC(0xd26560, 0xc000000180, 0x200000003, 0xc000000180)
    /home/zozu/go/pkg/mod/github.com/spf13/cobra@v1.1.3/command.go:960 +0x375
github.com/spf13/cobra.(*Command).Execute(...)
    /home/zozu/go/pkg/mod/github.com/spf13/cobra@v1.1.3/command.go:897
github.com/TheZoraiz/ascii-image-converter/cmd.Execute()
    /home/zozu/Stuff/Projects/ascii-image-converter/cmd/root.go:118 +0x31
main.main()
    /home/zozu/Stuff/Projects/ascii-image-converter/main.go:22 +0x25

In this example, i launch it on a docker ubuntu 18 running inside a linux gitlab runner. Any idea ?

TheZoraiz commented 2 years ago

Hey @lepapareil

ascii-image-converter checks for console dimensions (width and height) before creating an appropriately sized ascii art. Given your error log, this might be the problem. I'm assuming this fails because you're executing the command on a remote VM through gitlab runner, instead of doing it manually through a console with dimensions.

There is a library-only option to prevent terminal size checking if dimensions are specified, but I can also make it a CLI flag if you want it as a feature request.

junguler commented 2 years ago

hello, i was just about to open an issue asking for a flag to remove dimension restrictions, i would love such an option. also can you give an option to omit output in the terminal and only save externally? it looks cool but its unnecessary for me as i use your program for batch converting image sequences.

TheZoraiz commented 2 years ago

@junguler Sounds like a good idea. Will implement this asap.

lepapareil commented 2 years ago

Hi @TheZoraiz,

I have adjusted the dimensions and ...

$ ascii-image-converter --dimensions 1,1 ./logo.png

Error: set width must be lower than terminal width

So I totally agree with your proposal to add preventing terminal size checking flag. I think that it would be also great if we were able to prevent terminal size checking naturally when:

TheZoraiz commented 2 years ago

@lepapareil That actually sounds like a cleaner solution. Thanks for the input!

junguler commented 2 years ago

@TheZoraiz thank you, looking forward to it.

TheZoraiz commented 2 years ago

Just released v1.11.0 (snap version might take a while)

@junguler You should be able to save file in batches without printing if you supply the --only-save flag

@lepapareil It should work if you supply any one of --dimensions, --width or --height. Although, default usage or using --full will result in an error without terminal.

Let me know if it works on your end.

junguler commented 2 years ago

@TheZoraiz it works great, thanks, i'm in a process to write a tutorial markdown file for your program and this helps alot, i'll make sure to tag you with it when it's ready.

https://user-images.githubusercontent.com/59083599/136197185-497dce3e-b836-4cdc-baf7-6d3ebf4623b6.mp4

lepapareil commented 2 years ago

@lepapareil It should work if you supply any one of --dimensions, --width or --height. Although, default usage or using --full will result in an error without terminal. Let me know if it works on your end.

It works like a charm ❤️ thks for your work !

TheZoraiz commented 2 years ago

Glad to help :)

junguler commented 2 years ago

@TheZoraiz here it is as promised, thanks again for this great program of yours https://github.com/junguler/_image-manipulation/tree/main/Ascii-image-converter

TheZoraiz commented 2 years ago

@junguler Looks neat!

junguler commented 2 years ago

@TheZoraiz thank you <3