eumandy/eugtk/examples/test197.ex
2016-11-25 00:33:18 -07:00

84 lines
2.3 KiB
Elixir

-----------------------------------------------------------------------------
--# Saving a pixbuf in various formats:
-- this depends on which image formats your GTK library knows how to handle.
-- don't worry too much if it fails on some.
-- You won't often use this feature, and there are always other ways to
-- accomplish the same thing using external programs (Gimp).
------------------------------------------------------------------------------
include GtkEngine.e
constant docs = `
<u><b>Saving Pixbufs</b></u>
This loads an image of the mongoose, and
saves it in various formats, reporting
success or failure.
`
constant win = create(GtkWindow,{
{"border width",10},
{"connect","destroy","Quit"}})
object pb = create(GdkPixbuf,"thumbnails/mongoose.png")
constant panel = create(GtkBox,VERTICAL)
add(win,panel)
constant lbl = create(GtkLabel)
set(lbl,"markup",docs)
add(panel,lbl)
constant img = create(GtkImage,pb)
add(panel,img)
constant filetype = {
"jpeg","png","tiff","ico","bmp","gif"
}
constant box = create(GtkButtonBox)
pack(panel,-box)
constant quitbtn = create(GtkButton,"gtk-quit","Quit")
add(box,quitbtn)
constant okbtn = create(GtkButton,"insert-image#_Convert","SaveEm")
add(box,okbtn)
show_all(win)
main()
---------------------------------------------------------------------
function SaveFmt(atom img, sequence fname, sequence fmt, object opt=0)
-----------------------------------------------------------------------
if get(img,"save",canonical_path(fname),fmt,opt) then
return sprintf("\t%s\n",{fmt})
else
return sprintf("<span color='red'>\t%s failed\n</span>",{fmt})
end if
end function
-----------------------------------
global function SaveEm()
-----------------------------------
object list = "Saved in home directory:\n"
& SaveFmt(pb,"~/Goose.png","png","compression=5")
& SaveFmt(pb,"~/Goose.jpg","jpeg","quality=100")
& SaveFmt(pb,"~/Goose.ico","ico","depth=24")
& SaveFmt(pb,"~/Goose.bmp","bmp")
& SaveFmt(pb,"~/Goose.xpm","xpm")
& SaveFmt(pb,"~/Goose.gif","gif")
& SaveFmt(pb,"~/Goose.tif","tiff")
& SaveFmt(pb,"~/Goose.cgm","cgm")
& SaveFmt(pb,"~/Goose.svg","svg")
-- compression, quality, depth are optional, and only work on
-- the indicated formats
Info(win,"OK","Images converted",list,,,pb)
return 1
end function