croptoelie 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +30 -4
- data/VERSION +1 -1
- data/croptoelie.gemspec +2 -2
- data/lib/croptoelie.rb +11 -3
- metadata +3 -3
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# croptoelie
|
2
2
|
|
3
3
|
Content aware cropping.
|
4
4
|
|
@@ -10,18 +10,44 @@ Best results achieved in combination with scaling: the cropping is then only use
|
|
10
10
|
|
11
11
|
The trimming simply chops off te edge that is least interesting, and continues doing so, untill it reached the requested size.
|
12
12
|
|
13
|
-
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
Use it in [carrierwave][1], in a custom `manipulate!` block. For example, carrierwave in a Rails project:
|
16
|
+
|
17
|
+
File *uploaders/attachement_uploader.rb*:
|
18
|
+
|
19
|
+
def smart_crop_and_scale(width, height)
|
20
|
+
manipulate! do |img|
|
21
|
+
img = CropToelie.new(img)
|
22
|
+
img = img.smart_crop_and_scale(width, height)
|
23
|
+
img = yield(img) if block_given?
|
24
|
+
img
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Create different versions of your uploaded files:
|
29
|
+
version :thumb do
|
30
|
+
process :smart_crop_and_scale => [80, 80]
|
31
|
+
end
|
32
|
+
|
33
|
+
## Contributing to croptoelie
|
34
|
+
|
35
|
+
* This is one of my first more complex Ruby gems. So any help in general improvement is welcome. If you read the code and thing "OMG, what was he thinking, the answer is probably 'I wasn't'". Feel free to tell me so.
|
36
|
+
* RMagick is not the cleanest and leanest of all image-manipulation libraries in Ruby, but it was the only one where I found enough documentation and that had the features I needed (such as histograms). If you have better ideas, feel free to tell me them.
|
37
|
+
* I only use this gem with [carrierwave][1], so other implementations are probably not well done. If you want to use it in any other project, please tell me what I should change to make your life easier.
|
38
|
+
* The integration in carrierwave should be simpler. I would love to be able to say `process :smart_crop_and_scale` instead of having to use the smartcropper as class in a custom carrierwave `manipulate!` block. My knowledge of Ruby, Carrierwave and how to get this integration done properly is limited, if you have a patch, or a suggestion, that would be great!
|
14
39
|
|
15
40
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
16
41
|
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
17
42
|
* Fork the project
|
18
43
|
* Start a feature/bugfix branch
|
19
44
|
* Commit and push until you are happy with your contribution
|
20
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
21
45
|
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
22
46
|
|
23
|
-
|
47
|
+
## Copyright
|
24
48
|
|
25
49
|
Copyright (c) 2011 Bèr Kessels. See LICENSE.txt for
|
26
50
|
further details.
|
27
51
|
|
52
|
+
[1]: https://github.com/jnicklas/carrierwave
|
53
|
+
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/croptoelie.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{croptoelie}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Bèr Kessels"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-04-07}
|
13
13
|
s.description = %q{Crops images based on entropy: leaving the most interesting part intact. Don't expect this to be a replacement for human cropping, it is an algorythm and not an extremely smart one at that :). Best results achieved in combination with scaling: the cropping is then only used to square the image, cutting off the least interesting part. It offers two methods, scanning and trimming: with scanning the whole image is placed in an array then evaluated: very slow and memory-gobbling. The trimming simply chops off te edge that is least interesting, and continues doing so, untill it reached the requested size.}
|
14
14
|
s.email = %q{ber@webschuur.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/croptoelie.rb
CHANGED
@@ -5,9 +5,11 @@ class CropToelie
|
|
5
5
|
attr_accessor :orig
|
6
6
|
attr_accessor :step_size
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
# Create a new CropToelie object from a ImageList single image object.
|
9
|
+
# If you want to provide a file by its path use CropToelie.from_file('/path/to/image.png').
|
10
|
+
def initialize(image)
|
11
|
+
@image = image
|
12
|
+
@orig = image
|
11
13
|
|
12
14
|
# Hardcoded (but overridable) defaults.
|
13
15
|
@step_size = 10
|
@@ -19,6 +21,12 @@ class CropToelie
|
|
19
21
|
@rows = @image.rows
|
20
22
|
@columns = @image.columns
|
21
23
|
end
|
24
|
+
|
25
|
+
# Open create a croptoelie from a file on disk.
|
26
|
+
def self.from_file(image_path)
|
27
|
+
image = ImageList.new(image_path).last
|
28
|
+
return CropToelie.new(image)
|
29
|
+
end
|
22
30
|
|
23
31
|
# Crops an image to width x height
|
24
32
|
#
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: croptoelie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.3.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- "B\xC3\xA8r Kessels"
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-04-07 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -118,7 +118,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
118
118
|
requirements:
|
119
119
|
- - ">="
|
120
120
|
- !ruby/object:Gem::Version
|
121
|
-
hash: -
|
121
|
+
hash: -945638801
|
122
122
|
segments:
|
123
123
|
- 0
|
124
124
|
version: "0"
|