ss-attachment_fu 3.2.17

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,31 @@
1
+ module RedArtisan
2
+ module CoreImage
3
+ module Filters
4
+ module Effects
5
+
6
+ def spotlight(position, points_at, brightness, concentration, color)
7
+ create_core_image_context(@original.extent.size.width, @original.extent.size.height)
8
+
9
+ @original.spot_light :inputLightPosition => vector3(*position), :inputLightPointsAt => vector3(*points_at),
10
+ :inputBrightness => brightness, :inputConcentration => concentration, :inputColor => color do |spot|
11
+ @target = spot
12
+ end
13
+ end
14
+
15
+ def edges(intensity = 1.00)
16
+ create_core_image_context(@original.extent.size.width, @original.extent.size.height)
17
+
18
+ @original.edges :inputIntensity => intensity do |edged|
19
+ @target = edged
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def vector3(x, y, w)
26
+ OSX::CIVector.vectorWithX_Y_Z(x, y, w)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,25 @@
1
+ module RedArtisan
2
+ module CoreImage
3
+ module Filters
4
+ module Perspective
5
+
6
+ def perspective(top_left, top_right, bottom_left, bottom_right)
7
+ create_core_image_context(@original.extent.size.width, @original.extent.size.height)
8
+
9
+ @original.perspective_transform :inputTopLeft => top_left, :inputTopRight => top_right, :inputBottomLeft => bottom_left, :inputBottomRight => bottom_right do |transformed|
10
+ @target = transformed
11
+ end
12
+ end
13
+
14
+ def perspective_tiled(top_left, top_right, bottom_left, bottom_right)
15
+ create_core_image_context(@original.extent.size.width, @original.extent.size.height)
16
+
17
+ @original.perspective_tile :inputTopLeft => top_left, :inputTopRight => top_right, :inputBottomLeft => bottom_left, :inputBottomRight => bottom_right do |tiled|
18
+ @target = tiled
19
+ end
20
+ end
21
+
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ module RedArtisan
2
+ module CoreImage
3
+ module Filters
4
+ module Quality
5
+
6
+ def reduce_noise(level = 0.02, sharpness = 0.4)
7
+ create_core_image_context(@original.extent.size.width, @original.extent.size.height)
8
+
9
+ @original.noise_reduction :inputNoiseLevel => level, :inputSharpness => sharpness do |noise_reduced|
10
+ @target = noise_reduced
11
+ end
12
+ end
13
+
14
+ def adjust_exposure(input_ev = 0.5)
15
+ create_core_image_context(@original.extent.size.width, @original.extent.size.height)
16
+
17
+ @original.exposure_adjust :inputEV => input_ev do |adjusted|
18
+ @target = adjusted
19
+ end
20
+ end
21
+
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,47 @@
1
+ module RedArtisan
2
+ module CoreImage
3
+ module Filters
4
+ module Scale
5
+
6
+ def resize(width, height)
7
+ create_core_image_context(width, height)
8
+
9
+ scale_x, scale_y = scale(width, height)
10
+
11
+ @original.affine_clamp :inputTransform => OSX::NSAffineTransform.transform do |clamped|
12
+ clamped.lanczos_scale_transform :inputScale => scale_x > scale_y ? scale_x : scale_y, :inputAspectRatio => scale_x / scale_y do |scaled|
13
+ scaled.crop :inputRectangle => vector(0, 0, width, height) do |cropped|
14
+ @target = cropped
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ def thumbnail(width, height)
21
+ create_core_image_context(width, height)
22
+
23
+ transform = OSX::NSAffineTransform.transform
24
+ transform.scaleXBy_yBy *scale(width, height)
25
+
26
+ @original.affine_transform :inputTransform => transform do |scaled|
27
+ @target = scaled
28
+ end
29
+ end
30
+
31
+ def fit(size)
32
+ original_size = @original.extent.size
33
+ scale = size.to_f / (original_size.width > original_size.height ? original_size.width : original_size.height)
34
+ resize (original_size.width * scale).to_i, (original_size.height * scale).to_i
35
+ end
36
+
37
+ private
38
+
39
+ def scale(width, height)
40
+ original_size = @original.extent.size
41
+ return width.to_f / original_size.width.to_f, height.to_f / original_size.height.to_f
42
+ end
43
+
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,32 @@
1
+ module RedArtisan
2
+ module CoreImage
3
+ module Filters
4
+ module Watermark
5
+
6
+ def watermark(watermark_image, tile = false, strength = 0.1)
7
+ create_core_image_context(@original.extent.size.width, @original.extent.size.height)
8
+
9
+ if watermark_image.respond_to? :to_str
10
+ watermark_image = OSX::CIImage.from(watermark_image.to_str)
11
+ end
12
+
13
+ if tile
14
+ tile_transform = OSX::NSAffineTransform.transform
15
+ tile_transform.scaleXBy_yBy 1.0, 1.0
16
+
17
+ watermark_image.affine_tile :inputTransform => tile_transform do |tiled|
18
+ tiled.crop :inputRectangle => vector(0, 0, @original.extent.size.width, @original.extent.size.height) do |tiled_watermark|
19
+ watermark_image = tiled_watermark
20
+ end
21
+ end
22
+ end
23
+
24
+ @original.dissolve_transition :inputTargetImage => watermark_image, :inputTime => strength do |watermarked|
25
+ @target = watermarked
26
+ end
27
+ end
28
+
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,123 @@
1
+ require 'rubygems'
2
+ require 'osx/cocoa'
3
+ require 'active_support'
4
+
5
+ require 'red_artisan/core_image/filters/scale'
6
+ require 'red_artisan/core_image/filters/color'
7
+ require 'red_artisan/core_image/filters/watermark'
8
+ require 'red_artisan/core_image/filters/quality'
9
+ require 'red_artisan/core_image/filters/perspective'
10
+ require 'red_artisan/core_image/filters/effects'
11
+
12
+ # Generic image processor for scaling images based on CoreImage via RubyCocoa.
13
+ #
14
+ # Example usage:
15
+ #
16
+ # p = Processor.new OSX::CIImage.from(path_to_image)
17
+ # p.resize(640, 480)
18
+ # p.render do |result|
19
+ # result.save('resized.jpg', OSX::NSJPEGFileType)
20
+ # end
21
+ #
22
+ # This will resize the image to the given dimensions exactly, if you'd like to ensure that aspect ratio is preserved:
23
+ #
24
+ # p = Processor.new OSX::CIImage.from(path_to_image)
25
+ # p.fit(640)
26
+ # p.render do |result|
27
+ # result.save('resized.jpg', OSX::NSJPEGFileType)
28
+ # end
29
+ #
30
+ # fit(size) will attempt its best to resize the image so that the longest width/height (depending on image orientation) will match
31
+ # the given size. The second axis will be calculated automatically based on the aspect ratio.
32
+ #
33
+ # Scaling is performed by first clamping the image so that its external bounds become infinite, this helps when scaling so that any
34
+ # rounding discrepencies in dimensions don't affect the resultant image. We then perform a Lanczos transform on the image which scales
35
+ # it to the target size. We then crop the image to the traget dimensions.
36
+ #
37
+ # If you are generating smaller images such as thumbnails where high quality rendering isn't as important, an additional method is
38
+ # available:
39
+ #
40
+ # p = Processor.new OSX::CIImage.from(path_to_image)
41
+ # p.thumbnail(100, 100)
42
+ # p.render do |result|
43
+ # result.save('resized.jpg', OSX::NSJPEGFileType)
44
+ # end
45
+ #
46
+ # This will perform a straight affine transform and scale the X and Y boundaries to the requested size. Generally, this will be faster
47
+ # than a lanczos scale transform, but with a scaling quality trade.
48
+ #
49
+ # More than welcome to intregrate any patches, improvements - feel free to mail me with ideas.
50
+ #
51
+ # Thanks to
52
+ # * Satoshi Nakagawa for working out that OCObjWrapper needs inclusion when aliasing method_missing on existing OSX::* classes.
53
+ # * Vasantha Crabb for general help and inspiration with Cocoa
54
+ # * Ben Schwarz for example image data and collaboration during performance testing
55
+ #
56
+ # Copyright (c) Marcus Crafter <crafterm@redartisan.com> released under the MIT license
57
+ #
58
+ module RedArtisan
59
+ module CoreImage
60
+ class Processor
61
+
62
+ def initialize(original)
63
+ if original.respond_to? :to_str
64
+ @original = OSX::CIImage.from(original.to_str)
65
+ else
66
+ @original = original
67
+ end
68
+ end
69
+
70
+ def render(&block)
71
+ raise "unprocessed image: #{@original}" unless @target
72
+ block.call @target
73
+ end
74
+
75
+ include Filters::Scale, Filters::Color, Filters::Watermark, Filters::Quality, Filters::Perspective, Filters::Effects
76
+
77
+ private
78
+
79
+ def create_core_image_context(width, height)
80
+ output = OSX::NSBitmapImageRep.alloc.initWithBitmapDataPlanes_pixelsWide_pixelsHigh_bitsPerSample_samplesPerPixel_hasAlpha_isPlanar_colorSpaceName_bytesPerRow_bitsPerPixel(nil, width, height, 8, 4, true, false, OSX::NSDeviceRGBColorSpace, 0, 0)
81
+ context = OSX::NSGraphicsContext.graphicsContextWithBitmapImageRep(output)
82
+ OSX::NSGraphicsContext.setCurrentContext(context)
83
+ @ci_context = context.CIContext
84
+ end
85
+
86
+ def vector(x, y, w, h)
87
+ OSX::CIVector.vectorWithX_Y_Z_W(x, y, w, h)
88
+ end
89
+ end
90
+ end
91
+ end
92
+
93
+ module OSX
94
+ class CIImage
95
+ include OCObjWrapper
96
+
97
+ def method_missing_with_filter_processing(sym, *args, &block)
98
+ f = OSX::CIFilter.filterWithName("CI#{sym.to_s.camelize}")
99
+ return method_missing_without_filter_processing(sym, *args, &block) unless f
100
+
101
+ f.setDefaults if f.respond_to? :setDefaults
102
+ f.setValue_forKey(self, 'inputImage')
103
+ options = args.last.is_a?(Hash) ? args.last : {}
104
+ options.each { |k, v| f.setValue_forKey(v, k.to_s) }
105
+
106
+ block.call f.valueForKey('outputImage')
107
+ end
108
+
109
+ alias_method_chain :method_missing, :filter_processing
110
+
111
+ def save(target, format = OSX::NSJPEGFileType, properties = nil)
112
+ bitmapRep = OSX::NSBitmapImageRep.alloc.initWithCIImage(self)
113
+ blob = bitmapRep.representationUsingType_properties(format, properties)
114
+ blob.writeToFile_atomically(target, false)
115
+ end
116
+
117
+ def self.from(filepath)
118
+ raise Errno::ENOENT, "No such file or directory - #{filepath}" unless File.exists?(filepath)
119
+ OSX::CIImage.imageWithContentsOfURL(OSX::NSURL.fileURLWithPath(filepath))
120
+ end
121
+ end
122
+ end
123
+
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ss-attachment_fu
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.2.17
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Rick Olson
9
+ - Steven Pothoven
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2015-04-08 00:00:00.000000000 Z
14
+ dependencies: []
15
+ description: This is a fork of Steven Pothoven's attachment_fu including custom some
16
+ enhancements for Zoo Property
17
+ email: m.yunan.helmy@gmail.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files:
21
+ - README.rdoc
22
+ files:
23
+ - lib/pothoven-attachment_fu.rb
24
+ - lib/geometry.rb
25
+ - lib/technoweenie/attachment_fu.rb
26
+ - lib/technoweenie/attachment_fu/backends/cloud_file_backend.rb
27
+ - lib/technoweenie/attachment_fu/backends/s3_backend.rb
28
+ - lib/technoweenie/attachment_fu/backends/db_file_backend.rb
29
+ - lib/technoweenie/attachment_fu/backends/file_system_backend.rb
30
+ - lib/technoweenie/attachment_fu/processors/mini_magick_processor.rb
31
+ - lib/technoweenie/attachment_fu/processors/core_image_processor.rb
32
+ - lib/technoweenie/attachment_fu/processors/rmagick_processor.rb
33
+ - lib/technoweenie/attachment_fu/processors/gd2_processor.rb
34
+ - lib/technoweenie/attachment_fu/processors/image_science_processor.rb
35
+ - vendor/red_artisan/core_image/filters/effects.rb
36
+ - vendor/red_artisan/core_image/filters/perspective.rb
37
+ - vendor/red_artisan/core_image/filters/scale.rb
38
+ - vendor/red_artisan/core_image/filters/color.rb
39
+ - vendor/red_artisan/core_image/filters/quality.rb
40
+ - vendor/red_artisan/core_image/filters/watermark.rb
41
+ - vendor/red_artisan/core_image/processor.rb
42
+ - CHANGELOG
43
+ - LICENSE
44
+ - README.rdoc
45
+ - amazon_s3.yml.tpl
46
+ - rackspace_cloudfiles.yml.tpl
47
+ homepage: https://github.com/SoftwareSeniPT/attachment_fu
48
+ licenses: []
49
+ post_install_message:
50
+ rdoc_options:
51
+ - --inline-source
52
+ - --charset=UTF-8
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project: nowarning
69
+ rubygems_version: 1.8.23
70
+ signing_key:
71
+ specification_version: 2
72
+ summary: attachment_fu as a gem
73
+ test_files: []