Windows 10 has a preview function for TTF fonts.
Does there exist a program that does sorta the same but for TXF fonts?
Or does anyone know of a python function that can load such a font so I can write such a program myself, PILLOW didn't seem to support it.
Note: I tried showtxf.exe, but it show an image in too low resolution cannot really make out how the font looks.
I know I'm a little late. But I found this question AND the solution when searching for the answer to the same question.
txf seems to be a private file format for a bitmapped texture font which was/can be used in the context of GLUT by Marc Kilgard, an OpenGL toolkit in the late nineties.
The sourcecode and makefile are still around, along with a little instruction and a tool to generate(!) txf files from ttf font files. Also included is a txf-file viewer (source) where you are supposed to see all glyphs crammed into one coherent bitmap image, IIRC.
I found the source package at this link:
http://chateau-logic.com/content/ttf-txf-font-conversion
Related
I wanted to use Python to create animations (video) containing text and simple moving geometric objects (lines, rectangles, circles and so on).
In the book titled "Python 2.6 Graphics Cookbook" I found examples using Tkinter library. First, it looked like what I need. I was able to create simple animation but then I realized that in the end I want to have a file containing my animation (in gif or mp4 format). However, what I have, is an application with GUI running on my computer and showing me my animation.
Is there a simple way to save the animation that I see in my GUI in a file?
There is no simple way.
The question Programmatically generate video or animated GIF in Python? has answers related strictly to creating these files with python (ie: it doesn't mention tkinter).
The question How can I convert canvas content to an image? has answers related to saving the canvas as an image
You might be able to take the best answers from those two questions and combine them into a single program.
I've accomplished this before, but not in a particularly pretty way.
Tl;dr save your canvas as an image at each step of the iteration, use external tools to convert from image to gif
This won't require any external dependencies or new packages except having imagemagick already installed on your machine
Save the image
I assume that you're using a Tkinter canvas object. If you're posting actual images to the tk widgets, it will probably be much easier to save them; the tk canvas doesn't have a built-in save function except as postcript. Postscript might actually be fine for making the animation, but otherwise you can
Concurrently draw in PIL and save the PIL image https://www.daniweb.com/software-development/python/code/216929/saving-a-tkinter-canvas-drawing-python
Take a screenshot at every step, maybe using imagegrab http://effbot.org/imagingbook/imagegrab.htm
Converting the images to to an animation
Once the images are saved, I used imagemagick to dump them into either a gif, or into a mpg. You can run the command right from python using How to run imagemagick in the background from python or something similar. It also means that the process is implictely run on a separate thread, so it won't halt your program while it happens. You can query the file to find out when the process is done.
The command
convert ../location/*.ps -quality 100 ../location/animation.gif
should do the trick.
Quirks:
There are some small details, and the process isn't perfect. Imagemagick reads files in order, so you'll need to save the files so that alphabetical and chronological line up. Beware that the name
name9.ps
Is alphabetically greater than
name10.ps
From imagemagick's point of view.
If you don't have imagemagick, you can download it easily (its a super useful command-line tool to have) on linux and mac, and cygwin comes with it on windows. If you're worried about portability... well... PIL isn't standard either
There is a way of doing that, with the "recording screen method", this was explained in other question: "how can you record your screen in a gif?".
Click the link -->LICEcap : https://github.com/lepht/licecap
They say that it's free software for Mac (OS X) and Windows
You could look at Panda3D, but it could be a little over killed for what you need.
I would say you can use Blender3d too but i'm not really sure of how it works. Someone more experimented then me could tell you more about this.
Im using python turtle (Tkinter) to draw some lines which I need to export to a .jpg or .png file. To do so, I'm using python's turtle method to export my canvas to a postscript file:
pen.getcanvas().postscript(file="grafica.ps")
Where pen is just a fancy name for my turtle.
I get my .ps file, I convert it and... surprize! The image gets cut.
I tried some modifications like:
pen.getcanvas().postscript(file="grafica.ps", colormode='color', pagewidth=1600, pageheight=1200, width=1600, height=1200)
Since my turtle's window is 800x600 I thought that maybe twice as much space would be enough space to fit all the image but it still gets cut down...
I'm posting some output examples after the convertion, how my turtle's screen looks like when saving it, and how it should look exported.
Window while saving the image:
(Yes, there are sliders for the canvas)
How should it look:
And this is what I get:
I'm wondering how should I call postscript(), any idea?
I don't want to code this again on WxPython or other library :(
thanks!
This is probably a problem with ImageMagick interacting with the bounding box of the EPS file. My typical workflow for .eps files on Windows may be slightly convoluted, but it works. Similar thing should work for Linux. Install GhostScript (you'll have to make sure the GhostScript executables are on your path), then use the ps2pdf utility from the command line with the -dEPSCrop option:
ps2pdf -dEPSCrop input.eps output.pdf.
Then, use ImageMagick to convert the PDF to anything else, e.g. PNG
convert output.pdf output.png
You can control the PNG resolution etc. through ImageMagick. Like I said, convoluted, but it works.
I'm developing a CMS like application where the user should be able to create the menu the way he wants. Ideally, each menu object wouldn't be a text with a background but rather an image of the text. I envision this in either of these 2 ways:
a) By rendering a font in a/several image file/s with every letter and a script that given a word would give me either the sequence of images to string together or a single image file with the combination of all letters. I understand this could be done manually, but I feel there's probably a library to help with this.
b) With some kind of imaging library that would be able to render text with several blending effects such as gradient color, shadows, glow, etc. While I believe this one's a bit harder, maybe there's something that suits this need.
Any tips on any library that does this or anything similar?
Thanks in advance!
Bruno
We are using Imagemagick.
http://www.imagemagick.org/Usage/text/#attributes
This will render a simple button with text:
convert -background white -fill dodgerblue -font Candice -strokewidth 2 -stroke blue -undercolor lightblue -size 165x70 -gravity center label:Anthony label_color.gif
Wrapping this into a Python module is straight forward.
Although nowadays I'd settle to go with web fonts and CSS,a couple of years ago I faced this problem, and put together a small project that would generate text-within a templated image on the file, according to passed URL parameters.
The project is still publicized here: https://bitbucket.org/jsbueno/dynabutton -- it is made to work as a CGI script, but could be easily adapted to work with a more eficient server (I'd recomend some security tunning as well, if you are putting it online). You can also use it to generate all your images with a server side script, and just put the resulting image files online.
(it does use PIL underneath)
Ah yes, it can do shadow, and glow with proper parameters, can use any server-installed font, and will use an image template for providing the background, so you can apply any effect manually. (the included temlates, though, are quite amateurish)
Check out pycairo, bindings for the cairo rendering package. It can render text as well as graphics.
Well, with modern CSS techniques, the issue of nonmatching client-side fonts is less of a problem these days. Still there's demand for text-to-image tools.
PIL is often given as the answer to this question, but personally, I would give a good, hard look at pythonmagick as well. Pick the one that works best for you.
Actually the pygtk also has a pango renderer, as well.
I need a tile/sprite editor kind of like Pixen, but I couldn't find one for Windows so I thought it might be a good exercise for me to try and put one together. I use Python, so are there any libraries out there that are suited to the task of putting together a simple tile/sprite editor?
You just need a gui toolkit (gtk, qt, wx) a image library (PIL) and 500 hours of free time ...
Have you looked at the Python Imaging Library (PIL)?
So, the fact is that creating a complex app with a nice UI takes time - I am just expanding a little bit on the answer by THC4k.
PIL, at least PIL alone is useless for this: it does have some functions to manipulate images, but the complicate task here is creating and tunning your desired UI.
That's where the widgets toolkits come in: You would have to pick a toolkit platform that can offer you buttons, images, load and save the image files, maybe some specialzed widgets you can use to create your color swatches, etc.
both GTK+ and QT4.5 have a liberal license, are very complete and very unpythonic on their use :-(
(While you are at it, when using these libraries and toolkits our app can easily be multiplatform: you don't have to make it windows specific, it is equally easy to create an app that will run on Windows, Linux and Mac using python and either GTK+ or Qt4)
One thing I would suggest is for you to learn to proper use GIMP: it is an Image editor, and certainly it will lack a lot of tools you are needing for sprites: but you can expand it's capabilities with Python plug-ins. On the other hand GIMP does have thousands of features that you'd no longer will need to create for your stand-alone app. (think on layer support, color filters, image rotation etc...)
Check around on how to install GIMP with Python support on Windows, then spend some hours learning the app, with some book-like text around preferably so you can find the hidden features.
Ah, ok, finally:
If you want a very simple thing, just for the taste of "i did it" - you can use Pygame: You have to do all the drawing on the window, including text - but have straighter access to pixels, colors, mouse clicks and coordinates than with GTK+ or Qt, in a sense it would be a lot less of overhead for you to learn in terms of API's and internal working.
You could try PyGame but, seriously, you couldn't find a freeware graphics editor for Windows??!!
EDIT: In the past I've used Aha-Soft's IconXP for pixel work, but it costs USD 30 and doesn't offer all of the Pixen features that I guess you'll want.
I'm trying to write a font viewer for TrueType / OpenType fonts with VB6 / VB5 code (under Windows).
it is surprisingly difficult:
1) in VB / winAPI, i did not find how to extract the font's name, or font properties in general.
2) i can install the font (using AddFontResource API function), but then have to uninstall it. However, while (AddFontResource" expects a pathname, removing the font requires the font's name which is unknown to me.
is there a way to use an non-installed font ttf) ?
is there a way to extract a font's properties using vb6 ?
(I can write the program in wxPython but i know even less about fonts in python than with VB)
You could use the FreeType library.
It indeed is. I have faced the same problem myself (see my question). I ended up writing my own parser though because I needed to detect if the font was corrupt or not. There is a AddFontMemResourceEx function which:
When the function succeeds, the caller of this function can free the memory pointed to by pbFont because the system has made its own copy of the memory. To remove the fonts that were installed, call RemoveFontMemResourceEx. However, when the process goes away, the system will unload the fonts even if the process did not call RemoveFontMemResource.
Also, you can use the Font and Text Functions to get the font metrics.