#! /bin/sh # (not so) simple script to generate HTML gallery # ----------------------------------------------- # vermaden [AT] interia [DOT] pl # http://toya.net.pl/~vermaden/links.htm # set images per per value IMAGES_PER_PAGE=100 IMAGES_PER_ROW=3 # host for images/resources HOST=http://vermaden.go.pl # FreeBSD uses jot while Linux uses seq which jot 1> /dev/null 2> /dev/null || { alias jot=seq } # display basic usage if [ ${#} -ne 1 -o ! -d ${1} ]; then echo "usage: $( basename ${0} ) DIRECTORY" exit 1 fi header() { cat >> ${1} << EOF vermaden's resources
beastie
unix
beastie

vermaden's links / resources

updated: files: ${IMAGES_COUNT} generator: $( basename ${0} )
vermaden: links resources deviantart wallpapers screenshots
EOF } ie_part() { cat >> ${1} << EOF EOF } table_begin() { cat >> ${1} << EOF EOF } table_end() { cat >> ${1} << EOF
EOF } footer() { cat >> ${1} << EOF
EOF } WRKDIR=${1} FILELIST=files.htm # delete old index*.htm and thumb-* files rm -rf ${WRKDIR}/index* rm -rf ${WRKDIR}/thumb* rm -rf ${WRKDIR}/${FILELIST} # remove spaces from filenames ls ${WRKDIR} | while read FILE; do mv "$FILE" $( echo "$FILE" | tr '\ ' '_' ) > /dev/null 2>&1 done CLASS_PDF="[pP][dD][fF]" CLASS_IMAGES="[jJ][pP][eEgG][gG]*|[gG][iI][fF]|[pP][nN][gG]|[sS][vV][gG]" CLASS_MOVIES="[mM][oO][vV]|[aA][vV][iI]|[mM][pP][gGeE][gG]*|[fF][lL][vV]|[wW][mM][vV]" EXPR_PDF="^.*\.${CLASS_PDF}$" EXPR_MOVIES="^.*\.(${CLASS_MOVIES})$" EXPR_IMAGES="^.*\.(${CLASS_IMAGES})$" EXPRESSION="^.*\.(${CLASS_IMAGES}|${CLASS_PDF}|${CLASS_MOVIES})$" IMAGES_LIST=$( ls ${WRKDIR} | egrep "${EXPRESSION}" ) IMAGES_COUNT=0 for IMAGE in ${IMAGES_LIST} ;do IMAGES_COUNT=$(( ${IMAGES_COUNT} + 1 )) done # generate names for pages LINKS_DEFAULT="thumbnails / filelist" if [ ${IMAGES_COUNT} -gt ${IMAGES_PER_PAGE} ]; then CURRENT_PAGE=0 COUNT_LEFT=${IMAGES_COUNT} while [ ${COUNT_LEFT} -gt 0 ]; do if [ ${CURRENT_PAGE} -eq 0 ]; then LINKS="page: 0" else LINKS="${LINKS} / ${CURRENT_PAGE}" fi COUNT_LEFT=$(( ${COUNT_LEFT} - ${IMAGES_PER_PAGE} )); CURRENT_PAGE=$(( ${CURRENT_PAGE} + 1 )); done LINKS="${LINKS} / ${LINKS_DEFAULT}" else LINKS="${LINKS_DEFAULT}" fi LINKS="
${LINKS}

" # generate ${FILELIST} header ${WRKDIR}/${FILELIST} echo " ${LINKS}" >> ${WRKDIR}/${FILELIST} ie_part ${WRKDIR}/${FILELIST} echo " " >> ${WRKDIR}/${FILELIST} if echo "${IMAGES_LIST}" | egrep -q "${EXPR_IMAGES}"; then echo " " >> ${WRKDIR}/${FILELIST} echo "${IMAGES_LIST}" | egrep "${EXPR_IMAGES}" | while read IMG; do SIZE=$( du -shL "${WRKDIR}/${IMG}" | awk '{ print $1 }' ) echo " " >> ${WRKDIR}/${FILELIST} done fi if echo "${IMAGES_LIST}" | egrep -q "${EXPR_PDF}"; then echo " " >> ${WRKDIR}/${FILELIST} echo "${IMAGES_LIST}" | egrep "${EXPR_PDF}" | while read IMG; do SIZE=$( du -shL "${WRKDIR}/${IMG}" | awk '{ print $1 }' ) echo " " >> ${WRKDIR}/${FILELIST} done fi if echo "${IMAGES_LIST}" | egrep -q "${EXPR_MOVIES}"; then echo " " >> ${WRKDIR}/${FILELIST} echo "${IMAGES_LIST}" | egrep "${EXPR_MOVIES}" | while read IMG; do SIZE=$( du -shL "${WRKDIR}/${IMG}" | awk '{ print $1 }' ) echo " " >> ${WRKDIR}/${FILELIST} done fi echo "
 

images:
${SIZE}
${IMG}
 

documents:
${SIZE}
${IMG}
 

movies:
${SIZE}
${IMG}
" >> ${WRKDIR}/${FILELIST} echo " ${LINKS}" >> ${WRKDIR}/${FILELIST} footer ${WRKDIR}/${FILELIST} # generate index*.htm files CURRENT_PAGE=0 COUNT_LEFT=${IMAGES_COUNT} while [ ${COUNT_LEFT} -gt 0 ]; do SED_BEGIN=$(( 1 + ${IMAGES_COUNT} - ${COUNT_LEFT} )); SED_END=$(( ${IMAGES_PER_PAGE} + ${IMAGES_COUNT} - ${COUNT_LEFT} )); CURRENT_LIST=$( echo "${IMAGES_LIST}" | sed -n ${SED_BEGIN},${SED_END}p ); if [ ${CURRENT_PAGE} -eq 0 ]; then FILE=${WRKDIR}/index.htm else FILE=${WRKDIR}/index${CURRENT_PAGE}.htm fi header ${FILE} ie_part ${FILE} echo " ${LINKS}" >> ${FILE} table_begin ${FILE} for I in $( jot ${IMAGES_PER_PAGE} ); do IMAGE=$( echo "${CURRENT_LIST}" | sed -n ${I}p ) [ -z ${IMAGE} ] && break if echo "${IMAGE}" | egrep -q "${EXPR_IMAGES}"; then RESOLUTION=$( identify -format "%wx%h" ${WRKDIR}/${IMAGE} 2>/dev/null) elif echo "${IMAGE}" | egrep -q "${EXPR_MOVIES}"; then LENGTH=$( mplayer -identify -nosound -vo null -frames 1 ${WRKDIR}/${IMAGE} 2>&1 | grep ID_LENGTH | awk -F'=' '{print $2}' | awk -F'.' '{print $1}' ) MINUTES=$(( ${LENGTH} / 60 )) SECONDS=$(( ${LENGTH} % 60 )) RESOLUTION="${MINUTES}:${SECONDS}" else RESOLUTION="" fi TYPE=$( echo "${IMAGE}" | egrep -o "\.[a-zA-Z0-9]+$" | sed s/'\.'//1 | tr [:lower:] [:upper:] ) SIZE=$( du -shL "${WRKDIR}/${IMAGE}" | awk '{ print $1 }' ) echo " \"${IMAGE}\"
${RESOLUTION} ${SIZE} ${TYPE}" >> ${FILE} if [ $(( ${I} % ${IMAGES_PER_ROW} )) -eq 0 -a ${I} -lt ${IMAGES_PER_PAGE} ]; then echo " " >> ${FILE} fi done table_end ${FILE} echo " ${LINKS}" >> ${FILE} footer ${FILE} COUNT_LEFT=$(( ${COUNT_LEFT} - ${IMAGES_PER_PAGE} )); CURRENT_PAGE=$(( ${CURRENT_PAGE} + 1 )); done # generate image thumbnails for IMG in ${IMAGES_LIST} ;do if echo "${IMG}" | egrep -q "${EXPR_PDF}"; then convert -quality 60 "${WRKDIR}/${IMG}[0]" "${WRKDIR}/thumb-${IMG}.jpg" > /dev/null 2>&1 convert -thumbnail 120x90 -quality 60 ${WRKDIR}/thumb-${IMG}.jpg ${WRKDIR}/thumb-${IMG}.jpg > /dev/null 2>&1 elif echo "${IMG}" | egrep -q "${EXPR_IMAGES}"; then convert -background white -flatten -thumbnail 120x90 -quality 60 ${WRKDIR}/${IMG} ${WRKDIR}/thumb-${IMG}.jpg > /dev/null 2>&1 else mplayer -endpos 1 -frames 1 -nosound -vo jpeg:maxfiles=1:outdir=vergallery_tmp ${WRKDIR}/${IMG} > /dev/null 2>&1 mv vergallery_tmp/00000001.jpg ${WRKDIR}/thumb-${IMG}.jpg convert -thumbnail 120x90 -quality 60 ${WRKDIR}/thumb-${IMG}.jpg ${WRKDIR}/thumb-${IMG}.jpg > /dev/null 2>&1 rm -rf vergallery_tmp fi done # IMAGES # convert rose: -crop 20x20 +repage rose_tiles_%02d.gif # montage -mode concatenate -tile 4x rose_tiles_*.gif rose_rejoined.gif