[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libcaca] functional hacks to img2irc
Moinsen,
I'm currently using a patched aview from aalib to produce inline
images via a filter for replying to eMails with "mutt".
Looking around for alternatives, I came across img2irc, but it was
somehow not exactly what I needed (plain text), since it was
producing stupid mirc color codes. So I wanted to hack it to drop
the codes right where it produces them, but then I realized it was
just the "irc" export of several others. At first I was "yay", but
then went "d'oh", because among the various exporters is no plain
text one.
Can you please add one? :)
Please compare it to aview, images should be at least as
recognizable. (on 150x110 terminal ;)
In the meantime I hacked img2irc to accept a parameter to specify
which exporter to use, which would justify a rename to img2asc.
Default is now "ansi", because it lets me easily filter out the
ESC-codes to produce a plain text variant, but the result is still
inferior to aview, because cacaview probably depends on the missing
colors for best result.
Again, the attached patch for img2asc ;) is not perfect, but you get
the idea of what to change better.
You should probably remove the line
fprintf(stderr, "%s: loading %s\n", format, argv[1]);
because I used it only for testing.
I've also changed some defaults (80 rather than 60 cols), and the
ratio of x/y fontsize to better match my standard font.
This reminded me that it would be better if the font ratio could be
specified on the cmd-line, too. IIRC aview doesn't have that yet
either.
Have fun.
--
© Rado S. -- You must provide YOUR effort for your goal!
EVERY effort counts: at least to show your attitude.
You're responsible for ALL you do: you get what you give.
diff -ur libcaca-0.99.beta11/src/img2irc.c caca-rado/src/img2irc.c
--- libcaca-0.99.beta11/src/img2irc.c Fri Nov 10 16:37:33 2006
+++ caca-rado/src/img2irc.c Fri Oct 26 20:58:38 2007
@@ -38,8 +38,9 @@
unsigned long int len;
struct image *i;
int cols, lines;
+ char *format = "ansi";
- if(argc < 2 || argc > 3)
+ if(argc < 2 || argc > 5)
{
fprintf(stderr, "%s: wrong argument count\n", argv[0]);
usage(argc, argv);
@@ -49,6 +50,7 @@
if(!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))
{
fprintf(stderr, "%s: convert images to IRC file data\n", argv[0]);
+ fprintf(stderr, "use -f / --format: caca, ansi, html, html3\n");
usage(argc, argv);
return 0;
}
@@ -60,6 +62,13 @@
return 1;
}
+ if(!strcmp(argv[1], "-f") || !strcmp(argv[1], "--format"))
+ {
+ format = argv[2];
+ argc-=2;argv+=2;
+ fprintf(stderr, "%s: loading %s\n", format, argv[1]);
+ }
+
i = load_image(argv[1]);
if(!i)
{
@@ -70,8 +79,11 @@
/* Assume a 6Ã?10 font */
cols = argc == 3 ? atoi(argv[2]) : 0;
- cols = cols ? cols : 60;
+ cols = cols ? cols : 80;
+/*
lines = cols * i->h * 6 / i->w / 10;
+*/
+ lines = cols * i->h * 8 / i->w / 11;
cucul_set_canvas_size(cv, cols, lines);
cucul_set_color_ansi(cv, CUCUL_DEFAULT, CUCUL_TRANSPARENT);
@@ -80,7 +92,7 @@
unload_image(i);
- export = cucul_export_memory(cv, "irc", &len);
+ export = cucul_export_memory(cv, format, &len);
fwrite(export, len, 1, stdout);
free(export);