Convert .ttf file to .png - libgdx
Is there any way to convert a TTF to PNG files? Or any other method to create Sprite out of TTF file in LIBGDX framework? Is there any application available for it?
Before running
LibGDX has a built-in tool in the gdx-toolsproject called Hiero. Just run that project as a java application, and when asked which class to run, choose that one. It lets you take a .ttf file and render it the characters you need (in a size given in pixels), plus it generates a file that contains information about where each character is on the texture. In the program, it's very simple to initialize and use:
BitmapFont font = new BitmapFont(Gdx.files.internal("data/font/font.fnt"));
...
font.draw(spriteBatch, "Text to output", coordX, coordY);
(font.fnt is the file containing the texture positions and other relevant information, it also refers to the .png which is created in the same folder by default.)
You can take a look at the BitmapFont documentation here.
During runtime
A disadvantage of Hiero is that bitmap fonts don't really scale well, so they can look quite bad on different screen resolutions.
Take a look at this answer to a related question:
One solution is to use the FreeType extension to libgdx, as described here. This allows you to generate a bitmap font on the fly from a .ttf font. Typically you would do this at startup time once you know the target resolution.
I haven't personally used it, but it seems like something worth checking out. It looks very simple as well - the example code in the linked answer is 5 lines long.
Finally I got the solution to the same problem(TTF to PNG) which I faced too.
Follow the below steps,
1. Convert TTF to SVG
Use TTF to SVG conversion tool to convert your custom or downloaded TTF file to SVG file
2. Convert SVG to PNG/PDF/TTF:
Goto IcoMoon, in the top left corner, there will be button to Import Icons, click and upload your converted SVG file.
In the bottom bar, there will be an option "Generate SVG & More" as in the below image, click on it
Next, Click the Settings gear icon near "Download" option to override size, output formats(PDF,PNG,etc.,) and then close the Settings
Now click download to get the outputs into a single zip file !!!
A ttf is a true-type font. It is not a picture, but a vectoric character set. You can't convert it to a picture simply with a tool.
If you want to view/manipulate ttf files, you can do this with ttf editing tools, for example fontforge ( http://fontforge.sourceforge.net ).
This may be an old question, but I found the following batch file works with ImageMagick 7:
#ECHO OFF
set f=wingding.TTF
set ps=800
set bg=white
set ext=png
set s=600x600
set alpha=A B C D E F G H I J K L M N O P Q R S T U V W Z Y Z
set num=0 1 2 3 4 5 6 7 8 9
For %%X in (%alpha% %num%) do (
convert -font %f% -pointsize %ps% -size %s% -background %bg% label:%%X
%%X.%ext%)
pause
exit
NOTE: This conversion only works with a limited selection of font characters. It works well for all capital letters. Just install ImageMagick and make sure it is in your environment path. Include "legacy" commands in your installation.
Related
SVG rect to path [duplicate]
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations. Closed 4 years ago. Improve this question does anyone know of a tool that can take an SVG file, and convert it into an HTML 5 SVG path? you know, the d="M 0 0 L 20 134 L 233 24 Z" fill="#99dd79" part? I head here: Use Adobe Illustrator to create SVG Path using "move to" commands But not sure. Does this mean Illustrator can take any line drwaing and save it as an SVG path? Note: Yes there is inkscape, but I'm looking for gradient and masking support, if that's possible. I'd like to be able to utilize .ai files and export them using illustrator or Acrobat or something... is there something out there? Or is it built in to Illustrator or Acrobat as an output format?
Gimp can be used to convert SVGs with primitives (e.g. rects, circles, etc.) into a single path which can be used within HTML5. First download Gimp: https://www.gimp.org/downloads/ Export your SVG as a .svg file with any tool of choice e.g. Illustrator. Don't worry if the SVG output is messy for now, Gimp will clean it up Import the SVG file into Gimp with File -> Open, and the following (or similar) dialog should show up: Check both the Import Paths and Merge imported paths options Then go to Windows->Dockable Dialogues->Paths Right-click on the single path which says Imported Path and you should see the following dialog: Click Export Path... and save this text file to a location of your choice Locate and open up this file with a text editor of your choice e.g Notepad, TextEdit Copy the text within the <path d="copy this text here" /> Since Gimp formats the text with lots of spaces, you may need to re-format it, by removing some of the spaces to paste it into your HTML in a single line
Open the SVG with you text editor. If you have some luck the file will contain something like: <path d="M52.52,26.064c-1.612,0-3.149,0.336-4.544,0.939L43.179,15.89c-0.122-0.283-0.337-0.484-0.58-0.637 c-0.212-0.147-0.459-0.252-0.738-0.252h-8.897c-0.743,0-1.347,0.603-1.347,1.347c0,0.742,0.604,1.345,1.347,1.345h6.823 c0.331,0.018,1.022,0.139,1.319,0.825l0.54,1.247l0,0L41.747,20c0.099,0.291,0.139,0.749-0.604,0.749H22.428 c-0.857,0-1.262-0.451-1.434-0.732l-0.11-0.221v-0.003l-0.552-1.092c0,0,0,0,0-0.001l-0.006-0.011l-0.101-0.2l-0.012-0.002 l-0.225-0.405c-0.049-0.128-0.031-0.337,0.65-0.337h2.601c0,0,1.528,0.127,1.57-1.274c0.021-0.722-0.487-1.464-1.166-1.464 c-0.68,0-9.149,0-9.149,0s-1.464-0.17-1.549,1.369c0,0.688,0.571,1.369,1.379,1.369c0.295,0,0.7-0.003,1.091-0.007 c0.512,0.014,1.389,0.121,1.677,0.679l0,0l0.117,0.219c0.287,0.564,0.751,1.473,1.313,2.574c0.04,0.078,0.083,0.166,0.126,0.246 c0.107,0.285,0.188,0.807-0.208,1.483l-2.403,4.082c-1.397-0.606-2.937-0.947-4.559-0.947c-6.329,0-11.463,5.131-11.463,11.462 S5.15,48.999,11.479,48.999c5.565,0,10.201-3.968,11.243-9.227l5.767,0.478c0.235,0.02,0.453-0.04,0.654-0.127 c0.254-0.043,0.507-0.128,0.713-0.311l13.976-12.276c0.192-0.164,0.874-0.679,1.151-0.039l0.446,1.035 c-2.659,2.099-4.372,5.343-4.372,8.995c0,6.329,5.131,11.461,11.462,11.461c6.329,0,11.464-5.132,11.464-11.461 C63.983,31.196,58.849,26.064,52.52,26.064z M11.479,46.756c-4.893,0-8.861-3.968-8.861-8.861s3.969-8.859,8.861-8.859 c1.073,0,2.098,0.201,3.051,0.551l-4.178,7.098c-0.119,0.202-0.167,0.418-0.183,0.633c-0.003,0.022-0.015,0.036-0.016,0.054 c-0.007,0.091,0.02,0.172,0.03,0.258c0.008,0.054,0.004,0.105,0.018,0.158c0.132,0.559,0.592,1,1.193,1.05l8.782,0.727 C19.397,43.655,15.802,46.756,11.479,46.756z M15.169,36.423c-0.003-0.002-0.003-0.002-0.006-0.002 c-1.326-0.109-0.482-1.621-0.436-1.704l2.224-3.78c1.801,1.418,3.037,3.515,3.32,5.908L15.169,36.423z M25.607,37.285l-2.688-0.223 c-0.144-3.521-1.87-6.626-4.493-8.629l1.085-1.842c0.938-1.593,1.756,0.001,1.756,0.001l0,0c1.772,3.48,3.65,7.169,4.745,9.331 C26.012,35.924,26.746,37.379,25.607,37.285z M43.249,24.273L30.78,35.225c0,0.002,0,0.002,0,0.002 c-1.464,1.285-2.177-0.104-2.188-0.127l-5.297-10.517l0,0c-0.471-0.936,0.41-1.062,0.805-1.073h17.926c0,0,1.232-0.012,1.354,0.267 v0.002C43.458,23.961,43.473,24.077,43.249,24.273z M52.52,46.745c-4.891,0-8.86-3.968-8.86-8.858c0-2.625,1.146-4.976,2.962-6.599 l2.232,5.174c0.421,0.977,0.871,1.061,0.978,1.065h0.023h1.674c0.9,0,0.592-0.913,0.473-1.199l-2.862-6.631 c1.043-0.43,2.184-0.672,3.381-0.672c4.891,0,8.861,3.967,8.861,8.861C61.381,42.777,57.41,46.745,52.52,46.745z" fill="#241F20"/> The d attribute is what you are looking for.
Open the svg using Inkscape. Inkscape is a svg editor it is a bit like Illustrator but as it is built specifically for svg it handles it way better. It is a free software and it's available # https://inkscape.org/en/ ctrl A (select all) shift ctrl C (=Path/Object to paths) ctrl s (save (choose as plain svg)) done all rect/circle have been converted to path
(In reply to the "has the situation improved?" part of the question): Unfortunately, not really. Illustrator's support for SVG has always been a little shaky, and, having mucked around in Illustrator's internals, I doubt we'll see much improvement as far as Illustrator is concerned. If you're looking for DOM-style access to an Illustrator document, you might want to check out Hanpuku (Disclosure #1: I'm the author. Disclosure #2: It's research code, meaning there are bugs aplenty, and future support is unlikely). With Hanpuku, you could do something like: Select the path of interest in Illustrator Click the "To D3" button In the script editor, type: selection.attr('d', 'M 0 0 L 20 134 L 233 24 Z'); Click run If the change is as expected, click "To Illustrator" to apply the changes to the document Granted, this approach doesn't expose the original path string. If you follow the instructions toward the end of the plugin's welcome page, it's possible to edit the Illustrator document with Chrome's developer tools, but there will be lots of ugly engineering exposed everywhere (the SVG DOM that mirrors the Illustrator document is buried inside an iframe deep in the extension—changing the DOM with Chrome's tools and clicking "To Illustrator" should still work, but you will likely encounter lots of problems). TL;DR: Illustrator uses an internal model that's pretty different from SVG in a lot of ways, meaning that when you iterate between the two, currently, your only choice is to use the subset of features that both support in the same way.
Surprised no one mentioned Illustrator's Save As > Format dropdown > .svg option. Outputs an .svg file that contains the path (and the rest of the svg definition) within an .svg (xml) file. The path itself is within <path d>.
Plain text with .gif extension in Ubuntu
Well here´s the thing, I am using the Terminal to do this. With a text editor such as nano I create a plain text file with the content: "GIF89a2017" and I save it as rare.gif Here´s the thing, when I do file rare.gif it gives me this output: rare.gif: GIF image data, version 89a, 12338 x 14129 and that is indicating that it is a GIF image with a resolution of 12338 x 14129 and that's what I don't understand. Where´s that resolution coming from? Another thing is, I thought extension didn't really decide what type of file it is, for example when I take a .gif and convert it into and .exe it still recognises it as a GIF image with the file command. I'm gonna guess that in the problem that I have it is recognised as a GIF image because it was created with the GIF extension but I'd like to know why. Thanks to everyone!
Where´s that resolution coming from? It's coming from the (bogus) GIF89 header you put in the file. The four bytes following "GIF89a" define the width and height. Each one is stored as a 16-bit unsigned integer. The characters you put there -- 2017 -- are interpreted as: 32 30 ("20") -- 0x3032 = 12338 31 37 ("17") -- 0x3731 = 14129 I'm gonna guess that in the problem that I have it is recognised as a GIF image because it was created with the GIF extension but I'd like to know why. No, file doesn't look at extensions. It's because the file had a semi-valid GIF header. If you changed the header to something that didn't start with "GIF89a", it will no longer be recognized as a GIF.
TCL HTML File Viewer
I want to convert data from MySQL to HTML by using TCL. The real problem converting mysql data to html, showing that html in TCL viewer, can I host IE inside TCL canvas or some widget anything etc. I want to develop adhoc HTML-reporting module for an assignment. In short: I want to load/open/view HTML file in TCL. Any samples would be highly appreciated.
While you can't just make IE render on a canvas — too many things interact in unpleasant ways to make that impossible — you may well be able to use OpTcl to embed it in a window, which you can then put in a canvas if you choose. Here's the informative example from that page: package require optcl optcl::new -window .htm {http://wiki.tcl.tk} .htm config -width 800 -height 600 pack .htm This will manufacture an instance of the COM object for handling an HTTP URL (in this case, http://wiki.tcl.tk) and embed it in a Tk widget (.htm). If you were going to embed it in a canvas, you'd do: package require optcl canvas .canv optcl::new -window .canv.htm http://wiki.tcl.tk .canv create window 0 0 -anchor nw -window .canv.htm pack .canv Well, that's the minimum. You'd really do a bit more (adding scrollbars, etc.) There's a more extensive example on the Wiki too. (This doesn't appear to be a task for Tcom; that's designed to allow Tcl to interact with COM, but not really to allow Tk to embed widgets defined by it.) Be aware that I've not tested this on recent Windows systems or with recent versions of Tcl/Tk.
I want to convert data from MySQL to HTML by using TCL. With data from a table, you may be better off using the TkTable widget, sidestepping the conversion to HTML entirely. I want to load/open/view HTML file in TCL. There is a Tk-widget called TkHTML, which seems like it'll do just what you need.
Tesseract does not recognize single characters
How to represent: Create new image with paint (any size) Add letter A to this image Try to recognize -> tesseract will not find any letters Copy-paste this letter 5-6 times to this image Try to recognize -> tesseract will find all the letters Why?
You must set the "page segmentation mode" to "single char". For example, in Android you do the following: api.setPageSegMode(TessBaseAPI.pageSegMode.PSM_SINGLE_CHAR);
python code to do that configuration is like this: import pytesseract import cv2 img = cv2.imread("path to some image") pytesseract.image_to_string( img, config=("-c tessedit" "_char_whitelist=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" " --psm 10" " -l osd" " ")) the --psm flag defines the page segmentation mode. according to documentaion of tesseract, 10 means : Treat the image as a single character. so to recognize a single character you just need to use : --psm 10 flag.
You need to set Tesseract's page segmentation mode to "single character."
Have you seen this? https://code.google.com/p/tesseract-ocr/issues/detail?id=581 The bug list shows it as "no longer an issue". Be sure to have high resolution images. If you are resizing the image, be sure to keep a high DPI and don't resize too small Be sure to train your tesseract system use the baseApi.setVariable("tessedit_char_whitelist", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"); code before the init Tesseract Also, you may look into which font to use with OCR
AS3 - Copy image to clipboard
How to copy an image in AS3 to the clipboard? For text it works but I can't find a way to copy an image. System.setClipboard("my text")
You cannot. From the docs: Parameters string:String — A plain-text string of characters to put on the system Clipboard, replacing its current contents (if any). However, with Air you can use: Clipboard.setData() instead.