画像の一括ラベル付けとPicasaウェブアルバムへのアップロード

プロローグ



インターネットで画像を公開している人々は、おそらく少なくとも何らかの形で自分の著者であることを示す方法を考えました。



最も明白な方法の1つは、Webサイト、名前、著作権、またはコピーレフトを示す碑文を画像に追加することです。 このために、主婦はお気に入りのグラフィックエディタを開き、「テキスト」ツールを選択して、次世代に美しい文字でメッセージを書き込みます。



ただし、多くの画像がある場合、プロセスは非常に退屈になります。 そして、私たち、編集詩人およびコード彫刻家は創造的な人格であり、私たちはひどくルーチンを嫌います。



写真家、ブロガー、グラフォマニアックの2番目のルーチンは、居心地の良いホスティングに画像をアップロードすることです。



これをすべて自動化するために、考えられるすべてのオペレーティングシステム用に多くのツールが長い間発明されてきました。 しかし、これらのすべてのツールには1つの問題があります。作成者が正しいと思った方法でそれを実行します。



したがって、スクリプト。 したがって、私はLinuxが大好きです。 だからこそ、Picasaウェブアルバムが大好きです。Googleは、コマンドラインからGood Corporationサービスを操作するための非常に簡単なユーティリティであるgoogleclを提供しました(Habrで簡単に説明しました)。



スクリプトは非常にシンプルで、新しい予期しないニーズに簡単に適応します。





使い方





スクリプト( picasa-upload



と呼びましょう)はbashで実行され、次のように呼び出されます。

 picasa-upload [options] picture_dir [album_name]
      
      







ここに:



例:

 picasa-upload -DRs "/home/vassily/Pictures/ 2011" " 2011"
      
      







スクリプトの最初に、定数が設定されます。最大画像サイズ、通常の「小さな」ラベルへのパス、Picasaウェブアルバムのアカウント名。



碑文は、背景が透明なPNGで意味をなします。 スクリプトは、右下隅に90%の不透明度でオーバーレイします。 これはすべて、 composite



指定されたパラメーターを使用して簡単に変更できます。



必要条件







コンピューターのリスト



完全なスクリプトコードを以下に示します。



 #!/bin/bash #================================================================================ # Description # Script for automated upload of photos to Picasa Web Albums # Author # Dmitry Kann, http://yktoo.com/ # License # CC BY-SA 3.0 # Requires # ImageMagick # googlecl (http://code.google.com/p/googlecl/) #================================================================================ # Setup vars pic_size=1600 # Max size of the pictures to upload file_watermark="$HOME/Pictures/my-watermark.png" # Watermark file file_watermark_small="$HOME/Pictures/my-watermark-small.png" # 'Small' watermark file picasa_owner="vasily.poupkine" # Owner of the Picasa account #-------------------------------------------------------------------------------- # Functions #-------------------------------------------------------------------------------- # Logs a message # Parameters: # 1 - message log() { echo "$(date +%H:%M:%S) $1" } # Logs a normal message # Parameters: # 1 - message info() { log " $1" } # Logs a success message # Parameters: # 1 - message ok() { log "+ $1" } # Logs a failure message # Parameters: # 1 - message err() { log "- $1" exit 1 } # Displays usage info and exits # Parameters: # 1 - error message (if any) usage() { [ -z "$1" ] || log "- $1" cat << EOF Usage: $0 [options] photos_dir [album_name] Options: -D Do not delete the photos after uploading (leave them in the source dir) -R Do not resize photos to $pic_size pixels -U Do not upload the photos to Picasa (implies -D) -s Use "small" watermark instead of the default one (more appropriate for smaller images) album_name is mandatory unless -U is specified. EOF exit 2 } #-------------------------------------------------------------------------------- # Main routine #-------------------------------------------------------------------------------- # Parse command line options b_delete=1 b_resize=1 b_upload=1 s_watermark_to_use="$file_watermark" args=$(getopt -o DRUs -- "$@") [ $? -ne 0 ] && usage eval set -- $args for i; do case "$i" in -D) b_delete=0 shift ;; -R) b_resize=0 shift ;; -U) b_delete=0 b_upload=0 shift ;; -s) s_watermark_to_use="$file_watermark_small" shift ;; --) shift; break ;; esac done # Parse the rest of the command line dir_photos="$1" picasa_album_name="$2" # Check photos_dir [ ! -z "$dir_photos" ] || usage "Directory for photos is not specified" [ -d "$dir_photos" ] || err "Directory '$dir_photos' does not exist." # Check album_name [ $b_upload -eq 0 ] || [ ! -z "$picasa_album_name" ] || usage "Album name is not specified" [ $b_resize -ne 0 ] && convert_flags="-resize $pic_size" find "$dir_photos" -type f \( -iname '*.jpg' -o -iname '*.png' \) ! -name '*.picasaweb.*' -print | while read src_file; do dst_file=${src_file%\.*}.picasaweb.jpg info "Processing $src_file -> $dst_file" && # Resize and autorotate the image convert $convert_flags -quality 90 -auto-orient "$src_file" "$dst_file" && # Apply watermark composite -blend 90% -gravity southeast "$s_watermark_to_use" "$dst_file" "$dst_file" && # Upload the picture ( [ $b_upload -eq 0 ] || google picasa post "$picasa_album_name" "$dst_file" --owner "$picasa_owner" ) && # Remove the handled picture ( [ $b_delete -eq 0 ] || rm -f "$dst_file" ) done
      
      







私自身は地元ではないので、bashを数年しか学ばないので、コードに関するコメントを歓迎します。



All Articles