📜 ⬆️ ⬇️

Bulk labeling and uploading images in Picasa Web Albums

Prologue


People who publish images on the Internet, probably thought about how to somehow identify their authorship.

One of the most obvious ways is to add an inscription on your images with the indication of your website, name, copyright or copyleft. To do this, the housewife will open her favorite graphics editor, select the “Text” tool and write a beautiful letter to future generations.

However, if there are many images, the process becomes very tedious. And we, compilation poets and code sculptors, are creative personalities, we don’t like routine a lot.
')
The second routine operation of a graphomaniac blogger photographer is uploading images to a cozy hosting.

To automate all this, many tools have been invented long ago under all conceivable operating systems. But all these tools have one problem: they do it in the way that their creator seemed correct, and any deviations again lead to a lot of manual work.

Therefore, the script. Therefore, I love Linux. Therefore, I love Picasa Web Albums: Google gave us googlecl to tearing us apart - a very simple utility for working with the services of the Good Corporation from the command line (it was already briefly described in Habré).

The script is very simple and easily adapts to new unexpected needs.


How to use



The script (let's call it picasa-upload ) runs on bash and is invoked as follows:
 picasa-upload [options] picture_dir [album_name] 


Here:

For example:
 picasa-upload -DRs "/home/vassily/Pictures/ 2011" " 2011" 


At the very beginning of the script, constants are set: the maximum size of the image, the path to the usual and “small” lettering and the name of the account in Picasa Web Albums.

The inscription makes sense to make a PNG with a transparent background. The script imposes it with an opacity of 90% in the lower right corner. All this can be simply changed by the parameters specified for composite .

Requirements




Computer Program Listing


The full script code is below.

 #!/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 


I myself am not local, I have been learning bash for only a couple of years, so comments about the code are welcome.

Source: https://habr.com/ru/post/122859/


All Articles