Site do Cléber | Desisto de ter 10 blogs

image-count-2 – conta o número de imagens em um diretório

Esse é um script muito mais completo que o primeiro “image-count”. Ele tem uma porção de argumentos e, por identificar cada imagem e checar coisas como suas dimensões, é bem mais demorado.
Eu ainda não implementei um “help” para ele, mas as variáveis do início do arquivo tem nomes bem decentes.

Ah! Só para lembrar: você poderá mudar cada variável dessas, do início, via linha de comando. Tipo:

# image-count-2 dir minhas_fotos x_min_size 800 y_min_size 600

#!/bin/zsh

max_list_size=200

dir=”.”
x_min_size=400
y_min_size=300

print_small=0
print_ok=1
print_ok_names=0
print_count=1

debug=0

count=0

next=”"
for arg in $*;do

if [[ $next != "" ]];then
eval “$next=$arg”
next=”"
fi

case $arg in
max_list_size)
next=max_list_size
;;
x-size)
next=x_min_size
;;
y-size)
next=y_min_size
;;
dir)
next=dir
;;
print_small)
next=print_small
;;
print_ok)
next=print_ok
;;
print_count)
next=print_count
;;
debug)
next=debug
;;
print_ok_names)
next=print_ok_names
;;
help)
echo “Opções:”
echo “max_list_size x-size y-size dir print_small print_ok print_ok_names print_count debug”
exit 0
;;
esac
done

for subdir in $dir/*;do

if [[ ! -d $subdir ]];then
continue
fi

lista=($(printf “\”%s\” ” $subdir/**/*.jpg 2> /dev/null))
lista_size=$(print -ln $lista | wc -l)

if (($lista_size <= 0));then
continue
fi

if [[ $debug != 0 && $debug != "false" ]];then
print “lista_size: $lista_size”
fi

for ((i=0;i<$lista_size;i=i+$max_list_size));do

head=$((max_list_size + i))

lista_local=”"

lista_local_1=($(printf “\”%s\”\n” $lista | head -$head | tail -$max_list_size))

if [[ $debug != 0 && $debug != "false" ]];then
print -n “$i-”
fi

# Agrupa tudo numa linha só:
for item in $lista_local_1;do
lista_local=”$lista_local \”$item\”"
done

eval “identify $lista_local 2> /dev/null” | while read linha;do
linha=${linha/JPEG/=}
name=$(echo $linha | cut -d”=” -f1 )
size=$(echo $linha | cut -d”=” -f2 | cut -d” ” -f2)
x_size=$(echo $size | cut -d”x” -f1)
y_size=$(echo $size | cut -d”x” -f2)

if (($x_size >= $x_min_size && $y_size >= $y_min_size));then
if [[ $print_count != 0 && $print_count != "false" ]];then
count=$((count + 1))
fi
if [[ $print_ok_names != 0 && $print_ok_names != "false" ]];then
print “$name” | cut -d”[" -f1
fi
if [[ $print_ok != 0 && $print_ok != "false" ]];then
print “Ok: $name – $size – $x_size – $y_size”
fi
else
if [[ $print_small != 0 && $print_small != "false" ]];then
print “Too small: $name – $size – $x_size – $y_size”
fi
fi
done

done

done

print “”

if [[ $print_count != 0 && $print_count != "false" ]];then
print “Total ok: $count”
fi

Avaliação: 5 stars

Nenhum comentário ainda.

Leave a comment!

Paged comment generated by AJAX Comment Page

Ratings Plugin created by Jake Ruston.