también podéis escribir un texto en una imagen sin activar un componente gráfico provisto por gambas. Es posible por ejemplo usando unas funciones de la librería externa de Imlib2:
Library "libImlib2:1.4.6"
' Imlib_Image imlib_load_image_immediately(const char *file)
' Loads an image from disk located at the path specified by file.
Private Extern imlib_load_image_immediately(filename As String) As Pointer
' void imlib_context_set_image(Imlib_Image image)
' Sets the current image Imlib2 will be using with its function calls.
Private Extern imlib_context_set_image(Imlib_Image As Pointer)
' Imlib_Font imlib_load_font(const char * font_name)
' Loads a truetype font from the first directory in the font path that contains that font.
Private Extern imlib_load_font(font_name As String) As Pointer
' void imlib_context_set_font(Imlib_Font font)
' Sets the current font to use when rendering text.
Private Extern imlib_context_set_font(font As Pointer)
' void imlib_text_draw(int x, int y, const char * text)
' Draws the null-byte terminated string text using the current font on the current image
' at the (x, y) location (x, y denoting the top left corner of the font string)
Private Extern imlib_text_draw(x As Integer, y As Integer, text As String)
' void imlib_context_set_color(int red, int green, int blue, int alpha)
' Sets the color with which text, lines and rectangles are drawn when being rendered onto an image.
Private Extern imlib_context_set_color(red As Integer, green As Integer, blue As Integer, alpha As Integer)
' void imlib_image_set_format(const char * format)
' Sets the format of the current image. This is used for when you wish to save an image in a different format
' that it was loaded in, or if the image currently has no file format associated with it.
Private Extern imlib_image_set_format(formato_immagine As String)
' void imlib_save_image(const char *filename)
' Saves the current image in the format specified by the current image's format settings to the filename filename.
Private Extern imlib_save_image(filename As String)
Public Sub Main()
Dim ImlibImage, fnt As Pointer
ImlibImage = imlib_load_image_immediately("/ruta/del/fichero/imagen")
imlib_context_set_image(ImlibImage)
' Especifica la ruta del font TTF que queremos utilizar (por ejemplo: Ubuntu-B.ttf), y la dimensión del caracter:
fnt = imlib_load_font("/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-B.ttf/12")
If IsNull(fnt) Then Error.Raise("Error al cargar del font !")
' Elegimos un color para el texto (el ultimo a la derecha es el canal Alfa):
imlib_context_set_color(255, 255, 0, 255)
imlib_context_set_font(fnt)
' Escribe el texto especificando las sus coordinadas en la imagen:
imlib_text_draw(10, 20, "El nuestro texto")
' Especifica el tipo de fichero de imagen (por ejemplo "png"):
imlib_image_set_format("png")
imlib_save_image("/ruta/del/nuevo/fichero/imagen.png")
End
' Imlib_Image imlib_load_image_immediately(const char *file)
' Loads an image from disk located at the path specified by file.
Private Extern imlib_load_image_immediately(filename As String) As Pointer
' void imlib_context_set_image(Imlib_Image image)
' Sets the current image Imlib2 will be using with its function calls.
Private Extern imlib_context_set_image(Imlib_Image As Pointer)
' Imlib_Font imlib_load_font(const char * font_name)
' Loads a truetype font from the first directory in the font path that contains that font.
Private Extern imlib_load_font(font_name As String) As Pointer
' void imlib_context_set_font(Imlib_Font font)
' Sets the current font to use when rendering text.
Private Extern imlib_context_set_font(font As Pointer)
' void imlib_text_draw(int x, int y, const char * text)
' Draws the null-byte terminated string text using the current font on the current image
' at the (x, y) location (x, y denoting the top left corner of the font string)
Private Extern imlib_text_draw(x As Integer, y As Integer, text As String)
' void imlib_context_set_color(int red, int green, int blue, int alpha)
' Sets the color with which text, lines and rectangles are drawn when being rendered onto an image.
Private Extern imlib_context_set_color(red As Integer, green As Integer, blue As Integer, alpha As Integer)
' void imlib_image_set_format(const char * format)
' Sets the format of the current image. This is used for when you wish to save an image in a different format
' that it was loaded in, or if the image currently has no file format associated with it.
Private Extern imlib_image_set_format(formato_immagine As String)
' void imlib_save_image(const char *filename)
' Saves the current image in the format specified by the current image's format settings to the filename filename.
Private Extern imlib_save_image(filename As String)
Public Sub Main()
Dim ImlibImage, fnt As Pointer
ImlibImage = imlib_load_image_immediately("/ruta/del/fichero/imagen")
imlib_context_set_image(ImlibImage)
' Especifica la ruta del font TTF que queremos utilizar (por ejemplo: Ubuntu-B.ttf), y la dimensión del caracter:
fnt = imlib_load_font("/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-B.ttf/12")
If IsNull(fnt) Then Error.Raise("Error al cargar del font !")
' Elegimos un color para el texto (el ultimo a la derecha es el canal Alfa):
imlib_context_set_color(255, 255, 0, 255)
imlib_context_set_font(fnt)
' Escribe el texto especificando las sus coordinadas en la imagen:
imlib_text_draw(10, 20, "El nuestro texto")
' Especifica el tipo de fichero de imagen (por ejemplo "png"):
imlib_image_set_format("png")
imlib_save_image("/ruta/del/nuevo/fichero/imagen.png")
End