picasa-upload
) runs on bash and is invoked as follows: picasa-upload [options] picture_dir [album_name]
picasa-upload -DRs "/home/vassily/Pictures/ 2011" " 2011"
composite
.sudo apt-get install imagemagick
, or how you do it there).getopt
must support parameters with spaces. In other words, getopt -T; echo $?
getopt -T; echo $?
should output exactly 4. Neither more nor less. #!/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
Source: https://habr.com/ru/post/122859/
All Articles