mmb-iphone_polaroid 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.textile ADDED
@@ -0,0 +1,24 @@
1
+ Makes a picture from an iPhone camera look like a Polaroid. Adds date and
2
+ city and state where the picture was taken at the bottom.
3
+
4
+ !http://matthewm.boedicker.org/img/polaroid.jpeg!
5
+
6
+ Date is from EXIF data.
7
+
8
+ City and state are reverse geocoded from latitude and longitude in EXIF data.
9
+
10
+ Inspired by and some code borrowed from "RMagick Polaroid effect page":http://rmagick.rubyforge.org/Polaroid/polaroid.html
11
+
12
+ Font used in example is "Amaze":http://www.searchfreefonts.com/free/amaze.htm
13
+
14
+ Example usage:
15
+
16
+ <pre>
17
+ <code>
18
+ require 'iphone_polaroid'
19
+
20
+ img = Magick::Image::read('input.jpeg').first
21
+
22
+ img.polaroid.write('polaroid.jpeg')
23
+ </code>
24
+ </pre>
@@ -0,0 +1,19 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'iphone_polaroid'
3
+ s.version = '0.0.2'
4
+ s.date = '2009-04-05'
5
+ s.summary = 'Make iPhone camera pictures look like Polaroids'
6
+ s.email = 'matthewm@boedicker.org'
7
+ s.homepage = 'http://github.com/mmb/iphone_polaroid'
8
+ s.description = 'Post-process iPhone camera pictures with Polaroid effect adding date and location from EXIF.'
9
+ s.has_rdoc = false
10
+ s.authors = ['Matthew M. Boedicker']
11
+ s.files = [
12
+ 'lib/iphone_polaroid.rb',
13
+ 'README.textile',
14
+ 'iphone_polaroid.gemspec',
15
+ ]
16
+ s.add_dependency('exifr', ['> 0.0.0'])
17
+ s.add_dependency('json', ['> 0.0.0'])
18
+ s.add_dependency('rmagick', ['> 0.0.0'])
19
+ end
@@ -0,0 +1,125 @@
1
+ require 'open-uri'
2
+ require 'stringio'
3
+ require 'rubygems'
4
+ require 'exifr'
5
+ require 'json'
6
+ require 'RMagick'
7
+
8
+ module IPhonePolaroid
9
+
10
+ def lat_lon_to_city_state(lat, lon)
11
+ return open(
12
+ "http://maps.google.com/maps/geo?ll=#{lat},#{lon}&output=json") do |f|
13
+ json = JSON.parse(f.read)
14
+ aa_section = json['Placemark'].first['AddressDetails']['Country']['AdministrativeArea']
15
+ locality = aa_section['Locality']['LocalityName']
16
+ aa = aa_section['AdministrativeAreaName']
17
+ "#{locality}, #{aa}"
18
+ end
19
+ end
20
+
21
+ module_function :lat_lon_to_city_state
22
+
23
+ class Magick::Image
24
+
25
+ def exif
26
+ @exif ||= EXIFR::JPEG.new(StringIO.new(to_blob))
27
+ end
28
+
29
+ def lat
30
+ unless instance_variable_defined?(:@lat)
31
+ lat = exif.gps_latitude
32
+ unless lat.nil?
33
+ lat = lat[0] + lat[1] / 60.0 + lat[2] / 3600.0
34
+ lat *= -1 if exif.gps_longitude_ref == 'S'
35
+ end
36
+ @lat = lat
37
+ end
38
+ @lat
39
+ end
40
+
41
+ def lon
42
+ unless instance_variable_defined?(:@lon)
43
+ lon = exif.gps_longitude
44
+ unless lon.nil?
45
+ lon = lon[0] + lon[1] / 60.0 + lon[2] / 3600.0
46
+ lon *= -1 if exif.gps_longitude_ref == 'W'
47
+ end
48
+ @lon = lon
49
+ end
50
+ @lon
51
+ end
52
+
53
+ def polaroid(options={})
54
+ o = {
55
+ :photo_width => 216,
56
+ :photo_height => 225,
57
+ :border_color => '#e8eef3',
58
+ :border_width => 18,
59
+ :bottom_border_width => 63,
60
+
61
+ :text_fill => '#000000',
62
+ :text_font => 'Amaze-Normal',
63
+ :text_gravity => Magick::SouthGravity,
64
+ :text_size => 20,
65
+ :text_stroke => 'transparent',
66
+
67
+ :amplitude => 0.01,
68
+ :shadow_color => 'gray75',
69
+ :shadow_blur_radius => 0,
70
+ :shadow_blur_sigma => 3,
71
+ :shadow_composite_y => 5,
72
+ :rotate => -5,
73
+ }.merge(options)
74
+
75
+ img = copy
76
+
77
+ img.resize_to_fill!(o[:photo_width], o[:photo_height])
78
+
79
+ border = Magick::GradientFill.new(0, 0, 0, 0, o[:border_color],
80
+ o[:border_color])
81
+ border = Magick::Image.new(img.columns + o[:border_width] * 2,
82
+ img.rows + o[:border_width] + o[:bottom_border_width], border)
83
+ img = border.composite(img, Magick::NorthWestGravity, o[:border_width],
84
+ o[:border_width], Magick::OverCompositeOp)
85
+
86
+ caption = exif.date_time.strftime('%m/%d/%Y').sub(/(^|\/)0/, '\1')
87
+
88
+ unless lat.nil? or lon.nil?
89
+ caption =
90
+ "#{caption} #{IPhonePolaroid.lat_lon_to_city_state(lat, lon)}"
91
+ end
92
+
93
+ text = Magick::Draw.new
94
+ text.annotate(img, 0, 0, 0, o[:border_width], caption) {
95
+ self.fill = o[:text_fill]
96
+ self.font = o[:text_font]
97
+ self.gravity = o[:text_gravity]
98
+ self.pointsize = o[:text_size]
99
+ self.stroke = o[:text_stroke]
100
+ }
101
+
102
+ img.background_color = 'none'
103
+ amplitude = img.columns * o[:amplitude]
104
+ wavelength = img.rows * 2
105
+ img.rotate!(90)
106
+ img = img.wave(amplitude, wavelength)
107
+ img.rotate!(-90)
108
+
109
+ shadow = img.flop
110
+ shadow = shadow.colorize(1, 1, 1, o[:shadow_color])
111
+ shadow.background_color = 'white'
112
+ shadow.border!(10, 10, 'white')
113
+ shadow = shadow.blur_image(o[:shadow_blur_radius], o[:shadow_blur_sigma])
114
+ img = shadow.composite(img, -amplitude / 2, o[:shadow_composite_y],
115
+ Magick::OverCompositeOp)
116
+ img.rotate!(o[:rotate])
117
+ img.trim!
118
+
119
+ img
120
+
121
+ end
122
+
123
+ end
124
+
125
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mmb-iphone_polaroid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Matthew M. Boedicker
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-05 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: exifr
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: json
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.0.0
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: rmagick
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">"
42
+ - !ruby/object:Gem::Version
43
+ version: 0.0.0
44
+ version:
45
+ description: Post-process iPhone camera pictures with Polaroid effect adding date and location from EXIF.
46
+ email: matthewm@boedicker.org
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files: []
52
+
53
+ files:
54
+ - lib/iphone_polaroid.rb
55
+ - README.textile
56
+ - iphone_polaroid.gemspec
57
+ has_rdoc: false
58
+ homepage: http://github.com/mmb/iphone_polaroid
59
+ post_install_message:
60
+ rdoc_options: []
61
+
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ version:
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: "0"
75
+ version:
76
+ requirements: []
77
+
78
+ rubyforge_project:
79
+ rubygems_version: 1.2.0
80
+ signing_key:
81
+ specification_version: 2
82
+ summary: Make iPhone camera pictures look like Polaroids
83
+ test_files: []
84
+