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.
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(from_lang = nil, to_lang = nil) ⇒ Object
setzt IPTC-Keywords, enthalten in Datei <imagefilename>.tags wenn from_lang und to_lang uebergeben, dann Uebersetzung der Keywords z.B.
- #set_keywords_without_write(from_lang = nil, to_lang = nil) ⇒ Object
-
#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 |
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 |
# 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
112 113 114 115 116 |
# File 'lib/multistockphoto/photo.rb', line 112 def file_keywords photo = MiniExiftool.new @filename self. = photo. photo.keywords end |
#keywords ⇒ Object
Keywords aus Object-Attributen
107 108 109 |
# File 'lib/multistockphoto/photo.rb', line 107 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(from_lang = nil, to_lang = nil) ⇒ Object
setzt IPTC-Keywords, enthalten in Datei <imagefilename>.tags wenn from_lang und to_lang uebergeben, dann Uebersetzung der Keywords z.B. set_keywords(:de,:en)
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/multistockphoto/photo.rb', line 61 def set_keywords(from_lang=nil,to_lang=nil) ext = File.extname(@filename) if ext.upcase != '.JPG' and ext.upcase != '.JPEG' warn "cannot set Exif-Header with non-JPEG file #{@filename}" return end fn = @filename.sub(ext,".tags") lines=[] begin File.open(fn) {|f| lines = f.read } = Photo.(lines) if from_lang and to_lang = (,from_lang,to_lang) end self. = #print "writing tags to file ... " #$stdout.flush write_keywords #puts "done" rescue Errno::ENOENT #warn "WARNING: no tags file #{fn}" end end |
#set_keywords_without_write(from_lang = nil, to_lang = nil) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/multistockphoto/photo.rb', line 87 def set_keywords_without_write(from_lang=nil,to_lang=nil) 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) if from_lang and to_lang = (,from_lang,to_lang) end self. = rescue Errno::ENOENT #warn "WARNING: no tags file #{fn}" end end |
#write_keywords ⇒ Object
schreibt Keywords in Datei-Header
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/multistockphoto/photo.rb', line 119 def write_keywords photo = MiniExiftool.new @filename #s = '' #tags.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 #} # lieber durch Komma trennen, da sonst das Formular z.B. bei fotolia nicht # richtig gefüllt wird photo['keywords'] = .join(',') #TODO: photo['title'] = 'Testtitel' photo.save end |