This repository has been archived by the owner on Mar 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmark.rb
executable file
·111 lines (95 loc) · 3.32 KB
/
mark.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env ruby
require 'fileutils'
require 'rubygems'
require 'RMagick'
require 'mini_exiftool'
basedir = '/home/thomas/Ruby/'
inputdir = 'INPUT/'
outputdir = 'OUTPUT/'
portrait = 'mark.png' # Watermark for portrait-oriented shots
landscape = 'mark.png' # Watermark for landscape-oriented shots
square = 'mark.png' # Watermark for square shots
photographer = 'Thomas Bisset'
email = '[email protected]'
website = 'http://www.thomasbisset.co.uk'
count = 0
total = 0
puts ''
puts 'Requesting Set Details ...'
print 'Headline/Title? > '
headline = gets.chomp
print 'Caption? > '
caption = gets.chomp
print 'Location? > '
location = gets.chomp
print 'Keywords? (Comma Seperated) > '
keywords = gets.chomp
puts ''
for file in Dir.glob(basedir+inputdir+'*.{jpg,jpeg,JPG,JPEG}')
total = Dir.glob(basedir+inputdir+'*.{jpg,jpeg,JPG,JPEG}').count
count = count + 1
puts 'Adding ITPC Data to image %d of %d...' % [count, total]
data = MiniExiftool.new(file)
data["Author"] = photographer
data["Creator"] = photographer
data["By-line"] = photographer
data["Credit"] = photographer
data["Contact"] = email
data["Copyright"] = 'Copyright %s %s. All rights reserved.' % [photographer, Time.now.year]
data["CopyrightNotice"] = 'Copyright %s %s. All rights reserved.' % [photographer, Time.now.year]
data["CreatorWorkEmail"] = email
data["CreatorWorkURL"] = website
data["XPTitle"] = headline
data["Title"] = headline
data["Headline"] = headline
date = data["DateTimeOriginal"]
date = date.strftime('%A %e %B %Y').upcase # TO-DO: Add ordinals to string (1st, 2nd, 3rd, 4th etc)
data["Caption"] = '%s: %s (%s)' % [date, caption, location]
data["CaptionAbstract"] = '%s: %s (%s)' % [date, caption, location]
data["Location"] = location
data["Keywords"] = keywords
data.save
end
puts 'IPTC data entry complete'
puts ''
count = 0
total = 0
for file in Dir.glob(basedir+inputdir+'*.{jpg,jpeg,JPG,JPEG}')
total = Dir.glob(basedir+inputdir+'*.{jpg,jpeg,JPG,JPEG}').count
count = count + 1
puts 'Copying file %d of %d...' % [count, total]
FileUtils.cp(file, basedir+outputdir)
end
puts 'Copy Complete'
puts ''
puts 'Original files in '+basedir+inputdir
puts 'Web ready files in '+basedir+outputdir
puts ''
count = 0
total = 0
for file in Dir.glob(basedir+outputdir+'*.{jpg,jpeg,JPG,JPEG}')
total = Dir.glob(basedir+outputdir+'*.{jpg,jpeg,JPG,JPEG}').count
count = count + 1
img = Magick::Image::read(file).first
puts 'Watermarking Image %d of %d...' % [count, total]
if img.columns < img.rows # If in potrait orientation
src = Magick::Image.read(portrait).first
img = img.resize_to_fit(1200, 1200)
result = img.composite(src, Magick::SouthEastGravity, Magick::OverCompositeOp)
result.write(file)
elsif img.rows < img.columns # If in landscape orientation
src = Magick::Image.read(landscape).first
img = img.resize_to_fit(1200, 1200)
result = img.composite(src, Magick::SouthEastGravity, Magick::OverCompositeOp)
result.write(file)
elsif img.rows == img.columns # If square crop
src = Magick::Image.read(square).first
img = img.resize_to_fit(1200, 1200)
result = img.composite(src, Magick::SouthEastGravity, Magick::OverCompositeOp)
result.write(file)
else # If neither - return error
puts 'Error: ' + file + ' does not compute!'
end
end
puts 'Watermarking Complete'
puts ''