Class: Photo
- Inherits:
-
Object
- Object
- Photo
- Defined in:
- lib/multistockphoto/photo.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#rotated_filename ⇒ Object
readonly
Returns the value of attribute rotated_filename.
-
#tags ⇒ Object
Returns the value of attribute tags.
Class Method Summary collapse
-
.to_tags(s) ⇒ Object
erstellt Key-Array aus String (getrennt durch newline,‘,’ oder ‘ ’).
Instance Method Summary collapse
-
#drehen ⇒ Object
dreht Bild und schreibt in rot_…
-
#file_keywords ⇒ Object
ermittelt Keywords aus Datei.
-
#initialize(filename) ⇒ Photo
constructor
A new instance of Photo.
-
#keywords ⇒ Object
Keywords aus Object-Attributen.
-
#portrait? ⇒ Boolean
ist Bild im Hochformat TODO: paßt dieser Test für alle gedrehten Bilder?.
-
#set_keywords ⇒ Object
setzt IPTC-Keywords, enthalten in Datei <imagefilename>.tags.
-
#write_keywords ⇒ Object
schreibt Keywords in Datei-Header.
Constructor Details
#initialize(filename) ⇒ Photo
Returns a new instance of Photo.
10 11 12 13 |
# File 'lib/multistockphoto/photo.rb', line 10 def initialize(filename) @filename = filename @tags = nil end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
7 8 9 |
# File 'lib/multistockphoto/photo.rb', line 7 def filename @filename end |
#rotated_filename ⇒ Object (readonly)
Returns the value of attribute rotated_filename.
7 8 9 |
# File 'lib/multistockphoto/photo.rb', line 7 def rotated_filename @rotated_filename end |
#tags ⇒ Object
Returns the value of attribute tags.
8 9 10 |
# File 'lib/multistockphoto/photo.rb', line 8 def @tags end |
Class Method Details
.to_tags(s) ⇒ Object
erstellt Key-Array aus String (getrennt durch newline,‘,’ oder ‘ ’)
86 87 88 89 90 91 92 |
# File 'lib/multistockphoto/photo.rb', line 86 def self.(s) keys = [] s.split(/[, |\t\n]+/).each {|w| keys << w } keys end |
Instance Method Details
#drehen ⇒ Object
dreht Bild und schreibt in rot_… Datei
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/multistockphoto/photo.rb', line 44 def drehen pic = ImageList.new(@filename) if pic.orientation == LeftBottomOrientation b = File.basename(@filename) tmpname = @filename.sub(b,'') +'rot_' + b if not File.exist? tmpname pic.auto_orient! puts "rotating picture, writing to #{tmpname}" pic.write(tmpname) end @rotated_filename = tmpname end end |
#file_keywords ⇒ Object
ermittelt Keywords aus Datei
95 96 97 98 99 |
# File 'lib/multistockphoto/photo.rb', line 95 def file_keywords photo = MiniExiftool.new @filename self. = photo. photo.keywords end |
#keywords ⇒ Object
Keywords aus Object-Attributen
81 82 83 |
# File 'lib/multistockphoto/photo.rb', line 81 def keywords end |
#portrait? ⇒ Boolean
ist Bild im Hochformat TODO: paßt dieser Test für alle gedrehten Bilder?
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/multistockphoto/photo.rb', line 17 def portrait? if false pic = ImageList.new(@filename) if pic.orientation == LeftBottomOrientation return true else return false end end if true img = Magick::Image::read(@filename).first # p img begin if img.orientation == LeftBottomOrientation return true else return false end rescue puts "error in picture #{@filename}" return false # TODO: etwas gefaehrlich, bei nicht richtiger JPG-Datei # wuerde das auch zuenden end end end |
#set_keywords ⇒ Object
setzt IPTC-Keywords, enthalten in Datei <imagefilename>.tags
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/multistockphoto/photo.rb', line 60 def set_keywords ext = File.extname(@filename) fn = @filename.sub(ext,".tags") lines=[] begin File.open(fn) {|f| lines = f.read } puts "tags file #{fn} found" = Photo.(lines) self. = print "writing tags to file ... " $stdout.flush write_keywords puts "done" rescue Errno::ENOENT warn "WARNING: no tags file #{fn}" end end |
#write_keywords ⇒ Object
schreibt Keywords in Datei-Header
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/multistockphoto/photo.rb', line 102 def write_keywords photo = MiniExiftool.new @filename s = '' .each {|tag| if s == '' s = s + tag else # s = s + ' ' + tag # lieber durch Komma trennen, da sonst das Formular z.B. bei fotolia nicht # richtig gefüllt wird s = s + ',' + tag end } photo['keywords'] = s #TODO: photo['title'] = 'Testtitel' photo.save end |