Pastey Image Gallery

-- Simple example program in Euphoria language to create a html
-- page with all the picture files in the current directory. 
  
-- Marco Achury, 2008 
-- Released to public domain.  Feel free to use and modify. 
 
-- Updated for Eu 4.1b2 by Irv Mullins 
-- Added EuGTK interface Mar 21, 2019 
 
include GtkEngine.e 
include GtkFileSelector.e 
include std/filesys.e 
include std/datetime.e 
include std/net/url.e 
 
integer FN -- File number for output 
sequence input = sprintf("~/%s/*",{user_name}) -- default home 
sequence output = canonical_path("~/output.html") -- default in home 
 
constant 
    win = create(GtkWindow,"title=Gallery Maker,size=300x200,border=10,$destroy=Quit"), 
    pan = create(GtkBox,"orientation=vertical,spacing=10"), 
    lbl = create(GtkLabel,"Click the Open button to choose files, then click view"), 
    box = create(GtkButtonBox), 
    btn1 = create(GtkButton,"gtk-quit","Quit"), 
    btn2 = create(GtkButton,"gtk-open","SelectFolder"), 
    btn3 = create(GtkButton, "image=xviewer","ViewHTML") 
     
    gtk:add(win,pan) 
    gtk:add(pan,lbl) 
    gtk:add(box,{btn1,btn2,btn3}) 
    pack_end(pan,box) 
 
    show_all(win) 
    main() 
 
---------------------------------------------------------------------------------- 
global function SelectFolder() 
---------------------------------------------------------------------------------- 
fileselector:filters = {"images"} 
fileselector:show_preview = TRUE 
fileselector:select_multiple = TRUE 
input = fileselector:Open(input)  
 
GenerateHTML() 
 
return 1 
end function 
 
---------------------------------------------------------------------------------- 
global function GenerateHTML()  
---------------------------------------------------------------------------------- 
object fname, fdate, fpath = url:decode(input[1]) fpath = pathname(fpath[8..$]) 
object fpix, fsize 
 
FN = open (output, "w")  
if FN =-1 then Error(,,"Cannot open output file!") 
    abort(1) 
end if 
 
puts (FN, "<HTML>\n") 
puts (FN, " <HEAD>\n") 
puts (FN, sprintf("  <TITLE>Images from %s</TITLE>\n",{fpath})) 
 
puts (FN, "<style>\n") 
puts (FN, """ 

    div.quote { 
        display: block;  
        border: 1px solid black; 
        padding: 15px;  
        background: #D0D0D0;  
        margin: 5px;}\n""") 
puts (FN, "</style>\n") 
puts (FN, " </HEAD>\n\n") 
puts (FN, "<BODY>\n") 
 
puts (FN, "<H1>Image Gallery</H1>\n\n") 
puts (FN, sprintf("%d Files from %s in %s\n<br>\n<br>\n<hr>",{length(input),fpath,output})) 
 
puts (FN, "<table border='0'\n") 
puts (FN, "<tr height='400px'>\n") 
 
for i=1  to length(input) do 
     
    fname = url:decode(input[i]) 
    fname = locate_file(fname[8..$]) 
     
    fpix = create(GdkPixbuf,fname) 
    fsize = get(fpix,"size") 
    while fsize[1] > 300 or fsize[2] > 200 do 
    fsize = fsize * 0.9 
    end while 
     
    fdate = file_timestamp(fname)  
     
    printf(FN,"<td width='25%%'>\n<a href='%s'>\n",{fname}) 
    if fsize[1] > fsize[2] then 
        printf(FN,"<img src='%s' HEIGHT='%d'></a>\n",{fname,fsize[2]})   
    else 
        printf(FN,"<img src='%s' WIDTH='%d'></a>\n",{fname,fsize[1]}) 
    end if 
    puts(FN,"<br clear='all' />") 
    printf(FN,"<div class='quote' width='%d' align='bottom'>\n",fsize[1]) 
    printf(FN,"<small><b>Path:</b> %s </small><br />\n",{fpath}) 
    printf(FN,"<small><b>Name:</b> %s </small><br />\n",{filename(fname)}) 
     
    puts(FN,text:format("<small><b>File&nbsp;Size:</b> [,,] bytes</small><br>\n",file_length(fname))) 
     
    puts(FN,text:format("<small><b>Date:</b> []/[]/[] Time: []:[]:[]</small>\n</td>\n\n",fdate)) 
       
    if remainder(i,4)=0 then   
    puts (FN, "</div></tr>\n\n<tr>\n") 
    end if 
     
end for 
puts (FN, "</table>\n") 
 
printf(FN, "<address><b>Page generated: %s</b>",{datetime:format(now())}) 
puts (FN, " by a Euphoria powered script.</address>") 
puts (FN, "</BODY>\n</HTML>\n") 
close(FN) 
 
 set(lbl,"markup",text:format("<b>Input folder:</b> []\n<b>Output file:</b> [] has <b>[]</b> images.", 
        {fpath,output,length(input)})) 
 
return 1 
end function 
 
------------------------------- 
global function ViewHTML() 
------------------------------- 
    show_uri("file://" & output) 
return 1 
end function 
 
------------- END ------------ 
 

1. Comment by irv Apr 01, 2019

Better version can be found here:

https://openeuphoria.org/pastey/304.wc