Sha256: 767caa5bd1c62f0b7729ac38867c295b24bed91d10fc45826b83954b526195e3

Contents?: true

Size: 1.96 KB

Versions: 1

Compression:

Stored size: 1.96 KB

Contents

#!/usr/bin/env ruby

require "optparse"
require "methadone"
require "FlickrCollage.rb"

class App
  include Methadone::Main
  include Methadone::CLILogging
  include FlickrCollage

  main do |*args|
    dict    = Dictionary.new
    flickr  = Flickr.new(api_key: options[:api_key],
                         shared_secret: options[:shared_secret],
                         img_path: options[:path])
    img_width   = options.key?("width") ? options[:width].to_i : nil
    img_height  = options.key?("height") ? options[:height].to_i : nil
    image   = Image.new(img_path: options[:path],
                        collage_file: options[:file],
                        img_width: img_width,
                        img_height: img_height,
                        clear_tmp: !options[:save])
    photos  = []
    step    = 0

    while photos.size < FlickrCollage::IMG_COUNT
      keyword = step < args.size ? args[step] : dict.get_word

      photo = flickr.scrape(keyword: keyword)
      if Image.valid?(photo)
        info "Keyword: #{step + 1} #{keyword}: #{photo}"
        photos << photo
      else
        info "Keyword: #{step + 1} #{keyword}: no images found"
      end
      step += 1
    end

    info "Create collage #{image.collage_file}.jpg" if image.collage(files: photos)
    info "Finished: #{FlickrCollage::IMG_COUNT} images in #{step} steps"
  end

  description "Create collage from 10 top-rated Flickr images for your keywords"

  on("--api_key api_key", "Flickr api-key")
  on("--shared_secret shared_secret", "Flickr shared-secret")
  on("-w width", "--width width", "Set image width for crop")
  on("-e height", "--height height", "Set image height for crop")
  on("-p path", "--path path", "Path for collage")
  on("-f file", "--file file", "Filename for collage")
  on("-s", "--save", "Don't delete downloaded images")

  arg :keywords, :optional, "Your keywords for Flickr images"

  version FlickrCollage::VERSION

  use_log_level_option toggle_debug_on_signal: "USR1"

  go!
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
FlickrCollage-0.1.1 bin/FlickrCollage