Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'A script to create IMG tags from a folder of pictures' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A script to create IMG tags from a folder of pictures
Authored by: koncept on Dec 22, '04 02:27:28PM
I wrote this as a shell script for anybody who is interested. It will open the results in TextEdit

#!/bin/bash
###########################################################
# Usage: imgDetails.sh
#
# Script will save to /private/tmp/imgDetails_(PID).html 
# with the details of images it came across in the current 
# directory which the script was run. When complete, 
# the script will open the tmp file in textEdit.
############################################################
declare -r OUT=/private/tmp/imgDetails_$(echo $$).html
declare -r CMD="sips -g pixelWidth -g pixelHeight"
declare -a PROPS=()
declare -ar ALLOWED=(
*.jpg *.JPG *.jpeg
*.GIF *.gif
*.png *.PNG
)

let COUNT=0

for ITEM in ${ALLOWED[@]}; do
  if [ -f $ITEM ]; then
    pos=0
    for PROP in $($CMD "$ITEM"|tail -2|sed 's/ //g'|awk -F':' '{print $2}')
    do
      echo $PROP | egrep '[0-9]+'>/dev/null 2>&1
      if [ $? == 0 ]; then
        PROPS[$pos]=$PROP
        pos=$((pos+1))
      fi
    done
    if [ -n ${PROPS[0]} -a -n ${PROPS[1]} ]; then
      echo "<img src=\"${ITEM}\" width=\"${PROPS[0]}\" " \
        "height=\"${PROPS[1]}\" alt=\"${ITEM}\" />" | tee -a $OUT
      COUNT=$((COUNT+1))
    fi      
  fi
done

echo -e "\nAttempted to process (${COUNT}) files."

[ -f $OUT ] && open -e $OUT

exit 0


[ Reply to This | # ]
A script to create IMG tags from a folder of pictures
Authored by: koncept on Dec 22, '04 02:44:40PM
Made a slight change. I didn't see the ability to repost, so here it is again.

#!/bin/bash
#
###########################################################
# Usage: imgDetails.sh
#
# Script will save to /private/tmp/imgDetails_(PID).html 
# with the details of images it came across in the current 
# directory which the script was run. When complete, 
# the script will open the tmp file in textEdit.
############################################################
#
declare -i COUNT=0
declare -i SUCCESS=0
declare -r OUT=/private/tmp/imgDetails_$(echo $$).html
declare -r CMD="sips -g pixelWidth -g pixelHeight"
declare -ar ALLOWED=(*.jpg *.JPG *.jpeg *.GIF *.gif *.png *.PNG)

for ITEM in ${ALLOWED[@]}; do
  if [ -f $ITEM ]; then
    declare -i POS=0
    declare -a PROPS=()
    for PROP in $($CMD "$ITEM"|tail -2|sed 's/ //g'|awk -F':' '{print $2}')
    do
      echo $PROP | egrep '[0-9]+'>/dev/null 2>&1
      if [ $? == 0 ]; then
        PROPS[$POS]=$PROP
        POS=POS+1
      fi
    done
    if [ -n ${PROPS[0]} -a -n ${PROPS[1]} ]; then
      echo "<img src=\"${ITEM}\" width=\"${PROPS[0]}\" " \
        "height=\"${PROPS[1]}\" alt=\"${ITEM}\" />" | tee -a $OUT
      [ $? == 0 ] && SUCCESS=SUCCESS+1
    fi
    COUNT=COUNT+1
  fi
done

echo -e "\nAttempted to process (${COUNT}) files."
echo -e "Successfully processed (${SUCCESS}) files."

[ -f $OUT ] && open -e $OUT

exit 0


[ Reply to This | # ]