#! /bin/sh # This script creates tumbnails, reduced versions of large images, and an # index.html file pointing to all of it. # Design goals are # (1) exist in a single script that can be mailed around easily, etc. # (2) generate clean, simple, portable HTML # (3) no databases # (4) portable portable portable # There are many programs that violate some or all of these goals. They # are real neat, they make great web pages, they organize your life. They # don't fit in a single ugly Bourne shell script whose only point in life # is to take pictures off your digital camera and make them basically # presentable to your friends. # This script is in the public domain, share and enjoy. # The latest version is always at http://www.molenda.com/makethumbs/ # Written by Jason Molenda, 1998-09-13; rewritten less lamely 2001-10-26. ## Guidelines for hacking: ## ## Start at main() and trace the function calls from there. ## Remember that there is no scoping of variables, so local variables aren't. ## You'll see some function-local variables with common names ("$fn" etc) ## prefixed with an abbreviation of the function name so that they don't ## overwrite a similarly named variable in the caller. ## No cycles in the call graph or you'll lose. ## As much as I like Bourne shell, I probably should have just done this ## in perl or python. On the down side, whichever of those I pick, I'll ## hear constant whining from about half of my friends. No one likes ## Bourne shell, so it's the safest language choice. ## Return variables are prefixed with "RETURN_". Command line options ## are prefixed with "ARGV_". Defaults are prefixed with "DEFAULT_", ## and globals are prefixed with "GLOBAL_". ## GLOBAL_ will hold all the settings that we should act on. These came ## either from a DEFAULT_ or an ARGV_ if the user overrode the DEFAULT_. ## This script used to have no functions at all, but I found that annoying ## to maintain, so now I've embraced function-mania. main () { init_defaults read_dotrc_file find_needed make_dir_transversible "." parse_args $* get_image_list point_stdout_to_index_file progress_update_start_creating_index_html [ $GLOBAL_print_html_header_footer -eq 1 ] && print_html_header print_html_table_start iterate_over_image_list print_html_table_end [ $GLOBAL_print_html_header_footer -eq 1 ] && print_html_footer progress_update_done_creating_index_html [ $GLOBAL_create_slideshow -eq 1 ] && create_slideshow exit 0 } create_slideshow () { [ $GLOBAL_create_slideshow -eq 0 ] && return progress_update_start_creating_slideshow_pages remove_existing_slideshow_html_files create_slideshow_image_list while read fileset do prev=`echo "$fileset" | cut -d\| -f1` cur=`echo "$fileset" | cut -d\| -f2` next=`echo "$fileset" | cut -d\| -f3` create_slideshow_source_file "$prev" "$cur" "$next" if [ $GLOBAL_reduce_big_pics -eq 1 -a $GLOBAL_remove_originals -ne 1 ] then create_slideshow_reduced_file "$prev" "$cur" "$next" fi progress_update_created_slideshow_page done < $GLOBAL_slideshow_image_list progress_update_done_creating_slideshow_pages } create_slideshow_source_file () { cssf_prev_image="$1" cssf_cur_image="$2" cssf_next_image="$3" image_name_to_html_name "$cssf_cur_image" cssf_html_file="$RETURN_html_name" add_cleanup "$cssf_html_file" print_slideshow_file_header "$cssf_cur_image" "$cssf_html_file" print_slideshow_top_navlinks "$cssf_prev_image" "$cssf_cur_image" \ "$cssf_next_image" "source" "$cssf_html_file" print_slideshow_image "$cssf_cur_image" "$cssf_html_file" "source" print_slideshow_bottom_navlinks "$cssf_prev_image" "$cssf_cur_image" \ "$cssf_next_image" "source" "$cssf_html_file" print_slideshow_file_footer "$cssf_html_file" remove_cleanup "$cssf_html_file" } create_slideshow_reduced_file () { cssf_prev_image="$1" cssf_cur_image="$2" cssf_next_image="$3" cssf_cur_source_image="$cssf_cur_image" cssf_cur_reduced_image="$cssf_cur_image" if [ "$cssf_prev_image" != NULL ] then source_name_to_reduced_name "$cssf_prev_image" cssf_prev_image="$RETURN_reduced_name" fi source_name_to_reduced_name "$cssf_cur_image" cssf_cur_reduced_image="$RETURN_reduced_name" if [ -f "$RETURN_reduced_name" ] then cssf_cur_image="$RETURN_reduced_name" fi if [ "$cssf_next_image" != NULL ] then source_name_to_reduced_name "$cssf_next_image" cssf_next_image="$RETURN_reduced_name" fi image_name_to_html_name "$cssf_cur_reduced_image" cssf_html_file="$RETURN_html_name" add_cleanup "$cssf_html_file" print_slideshow_file_header "$cssf_cur_image" "$cssf_html_file" print_slideshow_top_navlinks "$cssf_prev_image" "$cssf_cur_image" \ "$cssf_next_image" "reduced" "$cssf_html_file" print_slideshow_image "$cssf_cur_image" "$cssf_html_file" "reduced" print_slideshow_bottom_navlinks "$cssf_prev_image" "$cssf_cur_image" \ "$cssf_next_image" "reduced" "$cssf_html_file" print_slideshow_file_footer "$cssf_html_file" remove_cleanup "$cssf_html_file" } print_slideshow_file_header () { psfh_image_file="$1" psfh_html_file="$2" get_file_english_name "$psfh_image_file" psfh_english_name="$RETURN_english_name" # The following exec goop so I don't have to manually redirect every # message to stderr in this function. exec 4>&1 # save stdout fd to fd #4 exec > "$psfh_html_file" # redirect stdout to stderr echo '' echo '' echo '
' echo "