dcamt

Publicado por Jean Michel 26/11/2004

[ Hits: 4.531 ]

Download dcamt.sh




Script para renomear, dimencionar, e organizar imagens
apartir de diretórios ou cameras digitais.

  



Esconder código-fonte

#!/bin/bash
#################################################################################
#                              #
# DCAMTOOLv2.0: Rename and resize your pictures.            #
# requeriments: grep, awk, imagemagick                  #
#                              #
#################################################################################
#   Copyright (C) 2004   Jean Michel Feltrin   feltrin@gmail.com      #
#                              #
#   This program is free software; you can redistribute it and/or modify   #
#   it under the terms of the GNU General Public License as published by   #
#   the Free Software Foundation; either version 2 of the License, or      #
#   (at your option) any later version.                  #
#                              #
#   This program is distributed in the hope that it will be useful,      #
#   but WITHOUT ANY WARRANTY; without even the implied warranty of      #
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the      #
#   GNU General Public License for more details.            #
#                              #
#   You should have received a copy of the GNU General Public License      #
#   along with this program; if not, write to the Free Software Foundation,   #
#   Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.      #
#                              #
#                              #
#################################################################################

echo -e "     _                     _"
echo -e "  __| | ___ __ _ _ __ ___ | |_"
echo -e " / _  |/ __/ _  | '_   _ \| __|"
echo -e "| (_| | (_| (_| | | | | | | |_"
echo -e " \__,_|\___\__,_|_| |_| |_|\__|"
echo -e

# Configures:
WDIR="$PWD"         # WORK DIRECTORY
TITLE="dsc"         # EVENT NAME
INUM=0            # INCREMENT NUMBER
RSIZE="640x480"         # RESIZE VALUE
ALBUM="/home/$USER/Album"   # Album colection Dir
TITLE=$(echo "$TITLE`date +%d%m%y`")
CDEV="/dev/sda1"      # Your Digital Camera Device


######################################################
# Album Configure
ALBUM="/home/$USER/Album"   # Album colection Dir
if [ ! -d $ALBUM ]; then
   mkdir $ALBUM
fi
YDATE=`date +%Y`
ptMES="Janeiro Fevereiro Março Abril Maio Junho Julho Agosto Setembro Outubro Novembro Dezembro"
cmes=0
for enPT in `echo $ptMES`; do
        let cmes=$cmes+1
        if [ $cmes = `date +%m` ]; then
                MDATE=$enPT
        fi
done
if [ ! -d  $ALBUM/$YDATE/$MDATE ]; then
   mkdir -p $ALBUM/$YDATE/$MDATE
fi
ABDIR=$ALBUM/$YDATE/$MDATE
######################################################

# Warning! if you set this options it'll copy all your 
# pictures from your memory stick to your machine
# CDIR THE DIR WITH THE CAM PICTURES
# you should check this directory according to your cam
CDIR="/mnt/cam/dcim/101msdcf" 


######################################################
if [ "`mount | grep $CDEV | awk '{print $1}'`" = "/dev/sda1" ]; then
   echo "Would you work on you digital camera pictures,"
   echo -n "it will copy all your camera file to: /tmp/dcamt/, would you ? (y/n):"
   read mfop
   MFFREE=`echo $mfop | tr [A-Z] [a-z]`         
   if [ $MSFREE != "N" ]; then
      if [ ! -d /tmp/dcamt ]; then
         mkdir /tmp/dcamt
      fi
      cp $CDIR/* /tmp/dcamt/
      WDIR="/tmp/dcamt"
   fi
fi

######################################################

if [ ! -z $1 ]; then
   TITLE="$1"
   TITLE=$(echo "$TITLE`date +%d%m%y`")
fi
if [ ! -z $2 ]; then
   RSIZE="$2"
   echo $RSIZE
   if [ $RSIZE = "1024x768" ]; then
      RSIZE="1024x768"
   elif [ $RSIZE = "800x600" ]; then
      RSIZE="800x600"
   elif [ $RSIZE = "640x480" ]; then
      RSIZE="640x480"
   else
      RSIZE="640x480"
   fi
fi
if [ ! -z $3 ]; then
#RENAME
   rlop="$3"
fi
if [ ! -z $4 ]; then
#SIZE
   lop="$4"
fi
if [ ! -z $5 ]; then
#MOVE
   mlop="$5"
fi
function showcf()
{
   echo
   echo "Configure:"
   echo -e "\t WORKDIR\t:[ $WDIR ]"
   echo -e "\t TITLE\t\t:[ $TITLE ]"
   echo -e "\t RESIZED VALUE\t:[ $RSIZE ]"
   echo "--------------------------------"
   echo
}
showcf
function conf()
{
   lcop=$6
   echo  -n "Would you change the configuration ? (y/n): "
   if [ -z $lcop ]; then
      read cop
      lcop=`echo $cop | tr [A-Z] [a-z]`      
   fi
   if [ "$lcop" = "y" ]; then
      echo "! To keep the default just press ENTER !"
      echo 
      echo -n "Workdir: "
      OWDIR=$WDIR
      read WDIR
      if [ -z $WDIR ]; then
         WDIR=$OWDIR
      fi
      echo -n "Title: "
      OTITLE=$TITLE
      read TITLE
      if [ -z $TITLE ]; then
         TITLE=$OTITLE
      fi
      echo -n "Resize: "
      OLDRSIZE=$RSIZE
      read RSIZE
      if [ -z $RSIZE ];then
         RSIZE=$OLDRSIZE
      fi
      echo
      showcf
   fi
}
conf

# RENAME THE FILE
if [ -z $rlop ]; then
   rlop=n
fi
while [ $rlop != "y" ];
do
   echo -n "Would you rename the files ? (y/n): "
   read op
   rlop=`echo $op | tr [A-Z] [a-z]`
   if [ $rlop = "y" ]; then
   
   for FILE in `ls $WDIR/*.jpg`
   do
      if [ $FILE = "dcamt.sh" ] || [ $FILE = "dcamt" ]; then
      continue
      fi
      let INUM=$INUM+1
      EVNUM=`echo "$TITLE-0"`
      RENAME=`echo "$EVNUM$INUM.jpg"`
      if [ "$FILE" != "$RENAME" ]; then
         echo "Renaming: $FILE to $RENAME"
         mv $FILE $WDIR/$RENAME
      else
         echo "RENAME: The files were with the same name."
         break
      fi
   done 
   #
   fi
   
   if [ $rlop = "n" ]; then
      break
   fi
done

# Image Size
if [ "$OSIZE" =  "$RSIZE" ]; then
echo "RESIZE: The files are with the same size."
else
if [ -z $lop  ]; then
   lop=n
fi
while [ $lop != "y" ];
do
   echo -n "Would you chage your images size $OSIZE to $RSIZE ? (y/n): "
   read op
   lop=`echo $op | tr [A-Z] [a-z]`
   if [ $lop = "n" ]; then
      break
   fi
done
if [ $lop = "y" ]; then
   for FILE in `ls $WDIR/*.jpg`
   do
      OSIZE=`convert -verbose $FILE /dev/null | head -n 1 | cut -d " " -f3 | cut -d "+" -f 1`
      echo "Converting $FILE with $OSIZE to $RSIZE"
      convert -size $OSIZE $FILE -resize $RSIZE $FILE
   done
fi
fi

# Move files to an other directory
if [ -z $mlop ]; then
   mlop=n
fi
while [ $mlop != "y" ];
do
   echo -n "Would you move all jpg files to $TITLE directory ? (y/n): "
   read op
   mlop=`echo $op | tr [A-Z] [a-z]`
   if [ $mlop = "n" ]; then
      break
   fi
done
if [ $mlop = "y" ]; then
   mkdir $WDIR/$TITLE
   for FILE in `ls *.jpg`
   do
      echo "Moving: $FILE..."
      mv $FILE $TITLE/
   done
   echo "All files were moved with sucess. Done"
   mv $WDIR/$TITLE/ $ABDIR/
fi

################################################

Scripts recomendados

pega IP de sua máquina na NET -DNA do ratinho

de - deep editor

Instala o JAVA 8 no Debian

Script de instalação para Firefox e Thunderbird - new release

Salvar link favorito


  

Comentários

Nenhum comentário foi encontrado.


Contribuir com comentário




Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts