4
$\begingroup$

I have a string in a .txt which I process as follow:

ks = Import["string.txt"];
Export["res", Style[ks, 8, Black, FontFamily -> "Courier"], "PNG", 
       ImageSize -> {8 sx, 4 sy}];

res = Import["res"];
Export["res.gif", res];

Here I have two problems. First, none of the monospaced fonts seems to make the end image look monospaced. (I believe this was somehow addressed in a previous question but no solution was found.) To get around this I thought for drawing the characters individually, but that would be resource-intensive. Is there a way to get real monospaced text from Wolfram?

The second problem is that the output images seem to have a fixed sized for the amount of characters that may fit in a line, therefore rendering partial lines of text. I think this is because of the way Mathematica imports the string but don't know how to solve it. An example is shown below.

I appreciate your help.


Sample input: http://pastebin.com/5ThLXw6L (Because it is long)

Sample output:

Output

Which comes from:

Original input

$\endgroup$

1 Answer 1

2
$\begingroup$

You can fix that by adjusting ItemSize with Grid

txt = Import["5ThLXw6L.txt", "Table"];
data = Flatten[Map[Characters, txt], 1];

Export["txt.png", 
  Grid[Map[Style[#, 20, Bold, FontFamily -> "Courier"] &, data, {2}], 
  Spacings -> 0, ItemSize -> {1, 2}]]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.