Fortunately, it's possible to run the file through any command-line formatters you'd like, then pipe the processed text into convert instead of reading directly from the file: fmt < ascii.txt | convert -size 1000x2000 xc:white -font "DejaVu-Sans-Condensed" \ ImageMagick won't wrap the text, so each line of text will extend its full length horizontally. If your text file isn't already formatted the way you need in order to render it (say, if it uses very long lines) then you may have to reformat it before handing it to convert. It's simpler to overestimate, though, as the only cost is convert consuming slightly more CPU and memory while processing.) Preprocessing Input (Obviously, 1000x2000 is excessive for small text files, and for longer ones at least the vertical dimension may need to be increased. The repage at the very end prevents the output PNG being created with an image offset, which would otherwise cause GIMP to pop up a dialog on load asking whether it should apply the offset. Will render into a 1000x2000 box, then trim off the excess white space except for a 10-pixel border all the way around the text. annotate 15 15 -trim -bordercolor "#FFF" -border 10 repage image.png The following command: convert -size 1000x2000 xc:white -font "FreeMono" -pointsize 12 -fill black \ I usually just pick excessive values, then take advantage of ImageMagick's -trim and -border to autocrop the result. Needing to guess the necessary dimensions of the output image can also be tedious. (There's no reason to increase the horizontal offset with larger font sizes, it has no relationship to the text dimensions.) I recommend going over by several pixels at least, so if you're using -pointsize 64 then you should pair that with something like -annotate 15 80. So if you don't shift the font down at least pointsize pixels, the top of the first line will be cut off. The second offset (vertical y-shift) must be at least equal to the point size of the font chosen (the argument to -pointsize), because ImageMagick will place the baseline of the font at the given offset. The first offset (horizontal x-shift) can be any positive integer, but needn't be greater than a few pixels. The arguments to -annotate (how far to shift the rendered text from the edge of the canvas) consist of horizontal and vertical pixel offsets (respectively). A list of the fonts available to any ImageMagick command can be obtained using the -list operator, so convert -list font will display all of the possible arguments to -font. The argument to -font can be any supported font name, if FreeMono isn't available (or simply isn't desired). Will output a rendered version of the given file contents, but without having to modify your "ascii.txt" file to contain the text 15x15 part of the -draw primitive. convert -size 360x360 xc:white -font "FreeMono" -pointsize 12 -fill black \ It's not as powerful as -draw, but for wholesale dumping of a text file's contents into an image it serves just fine. I find ImageMagick's -annotate operator to be a bit more convenient than the -draw method garethTheRed suggested, for the simple reason that it doesn't require modification of the input file. The font you choose should be a monospaced font, otherwise the text won't align. Single or double quotes will do, but make sure they're not used as part of your ascii-art as it will confuse matters. Also, make sure that the actual text to be converted is enclosed in quotes. With text 15,15 added as the first line of text (the 15,15 is a positional offset). Where ascii.txt is your ascii-art file:- text 15,15 ". Something similar to the following may help you:- convert -size 360x360 xc:white -font "FreeMono" -pointsize 12 -fill black -draw image.png Sorry, the link has expired.Imagemagick is your friend here. The uploaded file is password protected and cannot be converted. Please make sure there's at least a valid table sheet in your PDF. Opps! It looks like your file can't be converted. For encrypted PDFs, please Unlock PDF before uploading. Opps! Something went wrong…Please make sure the document you upload is not encrypted or blank and try it after a while. Only have 2 free tasks per 24 hours for free users.Upgrade to premium and continue processing this task. You can join EasePDF Premium membership to enjoy unlimited services. Your file has not been added because it exceeds the maximum file size of 10 MB. Sorry, you have exceeded the maximum file size. Your file has not been added because it exceeds the maximum file size of 5 MB.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |