D&C Lug - Home Page
Devon & Cornwall Linux Users' Group

[ Date Index ][ Thread Index ]
[ <= Previous by date / thread ] [ Next by date / thread => ]

Re: [LUG] batch mode jpeg conversion ?



Well, did you spot my "deliberate" mistake?

Thanks to whoever came up with the magic word "mogrify". Hopefully the
revised attached script will (a) work, and (b) make the thumbnails.

NB you need to have ImageMagick on your system, see if anything comes
up when you type "man mogrify".

Keith

#!/usr/bin/tclsh

#Here's a tcl script to make your html picture index. I've pretty much
#copied the html coding from your original page. I'm assuming that
#you've got a local mirror of your website and that this file has been
#copied to the directory where you want the html file and that pictures
#are in a subdirectory "pictures/big" and there's another subdirectory 
#"pictures/thumbnails" ready for the thumbnails, and that they're all jpegs.

#Remember to do "chmod 755 mkpixndx"

#Then execute with "mkpixndx lotsapix A Whole Load More Pix"
#This should create a file called "lotsapix.html" with the title
# "A Whole Load More Pix" (or whatever you substitute on your command line)

#NB The thumbnails take a while to process, so if you've got lots of
#pictures they'll take a while to cook.

# ---------------------------------------------------------------------------

# Take the first word of the command tail as the html filename
set filename [lindex $argv 0].html

#Open file for writing (if it already exists it will be trashed!)
set HTML [open $filename w]

#Write out the html header (remember to escape all the quotes)
puts $HTML "<!-- X-URL: http://www.eclipse.co.uk/morgad/$filename -->"
puts $HTML "<!-- Date: [exec date] -->"

#NOTE You may need to comment out the next line for local testing 
puts $HTML "<BASE HREF=\"http://www.eclipse.co.uk/morgad/$filename\";>\n"

puts $HTML "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\">"
puts $HTML "<HTML VERSION=\"3.2\">\n<HEAD>"
puts $HTML "<META NAME=\"author\" CONTENT=\"david r morgan\">"

#Use the remainder of the command tail as the html page title
puts $HTML "<TITLE>[lrange $argv 1 end]</TITLE>\n</HEAD>\n<BODY>\n"

#Write out a heading (here it's the same as the page title)
puts $HTML "<H1>[lrange $argv 1 end]</H1>\n" 

#Go to the directory with the pictures in it
cd pictures/big

#Work through a list of all the the jpegs ...
foreach pic [glob *.jp*] {

#get the file size
   set size [lindex [exec ls -s $pic] 0]K
   
#Make corresponding thumbnail
   puts "Creating thumbnail of $pic"
   exec cp $pic ../thumbnails/th_$pic
   exec mogrify -geometry 256x512 ../thumbnails/th_$pic

#Write the html code for each picture
   puts $HTML "<A HREF=\"pictures/big/$pic\">"
   puts $HTML "<IMG src=\"pictures/thumbnails/th_$pic\" ALT=\"$pic $size\""
   puts $HTML "BORDER=3 WIDTH=256 hspace=10 vspace=6 align=middle>"
   puts $HTML "$pic $size<\A><BR>\n"
}

#End the loop and change back to the directory you came from
cd ../..

#Finally write out the page bottom ...
puts $HTML <HR>
puts $HTML "<TABLE BORDER=\"0\" WIDTH=\"90%\" SUMMARY=\"bottom of window\">"
puts $HTML "<TR>\n<TD WIDTH=\"10%\"><A HREF=\"index.html\">home</A></td>"
puts $HTML "<TD WIDTH=\"10%\"></TD>\n<TD WIDTH=\"10%\"></TD>"
puts $HTML "<TD WIDTH=\"20%\"></TD>"
puts $HTML "<TD WIDTH=\"30%\"><sub>updated : \
<!-- datestamp:begin -->[exec date]<!-- datestamp:end --></sub></TD>"
puts $HTML "<TD WIDTH=\"10%\"></TD>"
puts $HTML "<TD WIDTH=\"10%\">\
<A HREF=\"mailto:morgad@xxxxxxxxxxxxx\";>email me</A></td>"

#Finish up the html code ...
puts $HTML "</TR>\n</TABLE>\n<HR>\n</BODY>\n</HTML>\n"

#And close the file
close $HTML

#End of File

Lynx friendly