From 7d7f4c42e1cc6ce63b5f579440d01f2405160d0c Mon Sep 17 00:00:00 2001 From: Jean-Yves Lamoureux Date: Wed, 7 Nov 2007 10:29:02 +0000 Subject: [PATCH] * Added switch to control output font size, and updated documentation accordingly --- doc/img2txt.1 | 14 ++++++++++++++ src/img2txt.c | 22 ++++++++++++++++------ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/doc/img2txt.1 b/doc/img2txt.1 index 53ce3d1..c778049 100644 --- a/doc/img2txt.1 +++ b/doc/img2txt.1 @@ -11,6 +11,14 @@ img2txt \- convert images to various text-based coloured files .B \-H .I height ] +[ +.B \-x +.I font-width +] +[ +.B \-y +.I font-height +] .PD 0 .IP .PD @@ -60,6 +68,12 @@ Change output column count. If not given, the default is set to 60. .B \-H, \-\-height= Change output line count. If not given, the height is computed to match correct aspect ratio. .TP +.B \-x, \-\-font-width= +Change output font width. If not given, the default is set to 6. This value will be used for computing aspect ratio. +.TP +.B \-y, \-\-font-height= +Change output font height. If not given, the default is set to 10. This value will be used for computing aspect ratio. +.TP .B \-b, \-\-brightness= Change image brightness. Default to 1.0. .TP diff --git a/src/img2txt.c b/src/img2txt.c index aeca510..69c3835 100644 --- a/src/img2txt.c +++ b/src/img2txt.c @@ -49,6 +49,8 @@ static void usage(int argc, char **argv) fprintf(stderr, " -v, --version\t\t\tVersion of the program\n"); fprintf(stderr, " -W, --width=WIDTH\t\tWidth of resulting image\n"); fprintf(stderr, " -H, --height=HEIGHT\t\tHeight of resulting image\n"); + fprintf(stderr, " -x, --font-width=WIDTH\t\tWidth of output font\n"); + fprintf(stderr, " -y, --font-height=HEIGHT\t\tHeight of output font\n"); fprintf(stderr, " -b, --brightness=BRIGHTNESS\tBrightness of resulting image\n"); fprintf(stderr, " -c, --contrast=CONTRAST\tContrast of resulting image\n"); fprintf(stderr, " -g, --gamma=GAMMA\t\tGamma of resulting image\n"); @@ -96,7 +98,7 @@ int main(int argc, char **argv) void *export; unsigned long int len; struct image *i; - unsigned int cols = 0, lines = 0; + unsigned int cols = 0, lines = 0, font_width = 6, font_height = 10; char *format = NULL; char *dither = NULL; float gamma = -1, brightness = -1, contrast = -1; @@ -115,15 +117,17 @@ int main(int argc, char **argv) { { "width", 1, NULL, 'W' }, { "height", 1, NULL, 'H' }, + { "font-width", 1, NULL, 'x' }, + { "font-height", 1, NULL, 'y' }, { "format", 1, NULL, 'f' }, { "dither", 1, NULL, 'd' }, { "gamma", 1, NULL, 'g' }, { "brightness", 1, NULL, 'b' }, { "contrast", 1, NULL, 'c' }, { "help", 0, NULL, 'h' }, - { "version", 0, NULL, 'v' }, + { "version", 0, NULL, 'v' }, }; - int c = mygetopt(argc, argv, "W:H:f:d:g:b:c:h:v", long_options, &option_index); + int c = mygetopt(argc, argv, "W:H:f:d:g:b:c:h:v:x:y:", long_options, &option_index); if(c == -1) break; @@ -135,6 +139,12 @@ int main(int argc, char **argv) case 'H': /* --height */ lines = atoi(myoptarg); break; + case 'x': /* --width */ + font_width = atoi(myoptarg); + break; + case 'y': /* --height */ + font_height = atoi(myoptarg); + break; case 'f': /* --format */ format = myoptarg; break; @@ -184,15 +194,15 @@ int main(int argc, char **argv) if(!cols && !lines) { cols = 60; - lines = cols * i->h * 6 / i->w / 10; + lines = cols * i->h * font_width / i->w / font_height; } else if(cols && !lines) { - lines = cols * i->h * 6 / i->w / 10; + lines = cols * i->h * font_width / i->w / font_height; } else if(!cols && lines) { - cols = lines * i->w * 10 / i->h / 6; + cols = lines * i->w * font_height / i->h / font_width; }