ScriptBasic > Tutorials
FreeImage
(1/1)
Support:
Here is an example of scripting the FreeImage library under Linux. FreeImage is also available for Windows.
[*]Get FreeImage version number
[*]Get FreeImage copyright message
[*]Load a jpg image
[*]Get the image height and width
[*]Rescale the jpg image from 225x225 to 100x100 using bicubic interpolation
[*]Save the rescaled image as a png
[*]Flip the original jpg image 180 degrees and save it as a png
[/list]
--- Code: ---DECLARE SUB DLL ALIAS "_idll" LIB "gtk-server"
DECLARE SUB VARPTR ALIAS "varptr" LIB "gtk-server"
DECLARE SUB REQUIRE ALIAS "_idll_require" LIB "gtk-server"
DECLARE SUB DEFINE ALIAS "_idll_define" LIB "gtk-server"
REQUIRE "libfreeimage.so"
DEFINE "FreeImage_GetVersion NONE STRING 0"
DEFINE "FreeImage_GetCopyrightMessage NONE STRING 0"
DEFINE "FreeImage_Load NONE LONG 3 INT STRING INT"
DEFINE "FreeImage_GetWidth NONE INT 1 LONG"
DEFINE "FreeImage_GetHeight NONE INT 1 LONG"
DEFINE "FreeImage_Rescale NONE LONG 4 LONG INT INT INT"
DEFINE "FreeImage_Save NONE BOOL 4 INT LONG STRING INT"
DEFINE "FreeImage_Rotate NONE LONG 3 LONG DOUBLE NULL"
CONST FIF_BMP = 0
CONST FIF_JPEG = 2
CONST FIF_PNG = 13
CONST FIF_GIF = 25
CONST FILTER_BICUBIC = 1
PRINT DLL("FreeImage_GetVersion"),"\n"
PRINT DLL("FreeImage_GetCopyrightMessage"),"\n"
fbmp = DLL("FreeImage_Load " & FIF_JPEG & " \"world.jpg\" 0")
PRINT "Width: ",DLL("FreeImage_GetWidth " & fbmp),"\n"
PRINT "Height: ",DLL("FreeImage_GetHeight " & fbmp),"\n"
fbmps = DLL("FreeImage_Rescale " & fbmp & " 100 100 " & FILTER_BICUBIC)
DLL("FreeImage_Save " & FIF_PNG & " " & fbmps & " \"world_small.png\" 0")
fbmpr = DLL("FreeImage_Rotate " & fbmp & " 180 0")
DLL("FreeImage_Save " & FIF_PNG & " " & fbmpr & " \"world_flip.png\" 0")
--- End code ---
Original .jpg image
Rescaled and converted to .png
Flipped 180 degrees
jrs@laptop:~/sb/FreeImage$ scriba fi.sb
3.13.1
This program uses FreeImage, a free, open source image library supporting all common bitmap formats. See http://freeimage.sourceforge.net for details
Width: 225
Height: 225
jrs@laptop:~/sb/FreeImage$
Support:
If you define the library in your program like I did in the FreeImage example and use my version of the GTK-Server extension module, you don't need the gtk.bas include. (SB module) Attached is the 32 bit version of gtk-server.so for Ubuntu.
--- Quote ---Will the same gtk.bas work for windows as well linux
--- End quote ---
I have some recent Windows/Linux Gtk-Server examples HERE.
Navigation
[0] Message Index
Go to full version