allthumbs 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2011 John Bresnik and The Barbarian Group, LLC
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,32 @@
1
+ =Allthumbs
2
+
3
+ Gots tons of thumbnails clogging up your requests? Why merge them all into a single image / single request?
4
+
5
+ =Dependencies
6
+
7
+ Library is whole dependent on Image Magick for processing files, the gem will let you know if it can't find the necessary binaries
8
+
9
+ =Usage Examples
10
+
11
+ * After Save callback in Rails 3, using paperclip to regenerate an image based on changes
12
+
13
+ after_save :generate_thumbnail_image
14
+ def generate_thumbnail_image
15
+ Allthumbs.generate (all.map {|x| x.image.path }), "#{RAILS_ROOT}/public/images/thumbnail-image.jpg", { :row => 3, :border => 2 }
16
+ end
17
+
18
+ =Tests
19
+
20
+ Comes with a complete rspec suite:
21
+
22
+ $ rake test
23
+
24
+ =Todo
25
+
26
+ Develop some kind of helper to assist in generation of supporting HTML, e.g. you would like have rollovers or popups for each thumbnail
27
+
28
+ =Thanks
29
+
30
+ * Thoughtbot (heavily influenced by paperclip)
31
+ * Rick Webb (championing the open source cause)
32
+
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'rake'
5
+ require 'rake/testtask'
6
+ require 'rake/rdoctask'
7
+
8
+ $LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')
9
+ require 'allthumbs'
10
+
11
+ desc 'Default: run unit tests.'
12
+ task :default => [:clean, :all]
13
+
14
+ desc 'Test the allthumbs plugin.'
15
+ Rake::TestTask.new(:test) do |t|
16
+ t.libs << 'lib' << 'profile'
17
+ t.pattern = 'test/**/*_test.rb'
18
+ t.verbose = true
19
+ end
20
+
21
+ desc 'Start an IRB session with all necessary files required.'
22
+ task :shell do |t|
23
+ chdir File.dirname(__FILE__)
24
+ exec 'irb -I lib/ -I lib/allthumbs -r rubygems -r tempfile -r init'
25
+ end
26
+
27
+ desc 'Clean up files.'
28
+ task :clean do |t|
29
+ FileUtils.rm_rf "tmp"
30
+ FileUtils.rm "test/debug.log" rescue nil
31
+ Dir.glob("allthumbs-*.gem").each{|f| FileUtils.rm f }
32
+ end
33
+
34
+ desc 'Build the gemspec.'
35
+ task :gemspec do |t|
36
+ exec 'gem build allthumbs.gemspec'
37
+ end
38
+
39
+ desc "Print a list of the files to be put into the gem"
40
+ task :manifest => :clean do
41
+ spec.files.each do |file|
42
+ puts file
43
+ end
44
+ end
45
+
46
+ desc "Generate a gemspec file for GitHub"
47
+ task :gemspec => :clean do
48
+ File.open("#{spec.name}.gemspec", 'w') do |f|
49
+ f.write spec.to_ruby
50
+ end
51
+ end
52
+
53
+ desc "Build the gem into the current directory"
54
+ task :gem => :gemspec do
55
+ `gem build #{spec.name}.gemspec`
56
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), "lib", "allthumbs")
@@ -0,0 +1,26 @@
1
+ require 'cocaine'
2
+ module Allthumbs
3
+ # Generates the montage image for a list of file paths
4
+ # * options
5
+ # :border - surrounding border for each thumbnail in pixels
6
+ # :row - number of thumbnails per row
7
+ # :column - number of thumbnails per column
8
+ def self.generate files, out, options = {}
9
+ row = options[:row]
10
+ column = options[:column]
11
+ border = options[:border]
12
+
13
+ raise "Incorrect number of files for specified row and column lengths" if files.size != (row * column) if row and column
14
+ files.split.map { |file| raise "Attempting to generate with one or more invalid files" unless File.exists? file }
15
+
16
+ begin
17
+ command = Cocaine::CommandLine.new(
18
+ "montage", "-geometry :geometry -tile :tile :files",
19
+ :geometry => "+#{border}+#{border}", :tile => "#{column}x#{row}", :files => (files += " #{out}")).command
20
+ `#{command.gsub(/'/, '')}`
21
+ rescue Cocaine::CommandNotFoundError => e
22
+ raise "Could not run the 'montage' command. Please install ImageMagick."
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,6 @@
1
+ module Allthumbs
2
+ # We're doing this because we might write tests that deal
3
+ # with other versions of bundler and we are unsure how to
4
+ # handle this better.
5
+ VERSION = "0.0.1" unless defined?(::Bundler::VERSION)
6
+ end
@@ -0,0 +1,2 @@
1
+ namespace :allthumbs do
2
+ end
@@ -0,0 +1,46 @@
1
+ require './test/helper'
2
+
3
+ class AllthumbsTest < Test::Unit::TestCase
4
+ context "Testing montage creation" do
5
+ setup do
6
+ assert IMAGES.size == 12
7
+ end
8
+ end
9
+ should "generate a single 4 column (104x78) montage from 12 22px images with 2 pixel borders" do
10
+ Allthumbs.generate(IMAGES, TESTMONTAGE, { :column => 4, :border => 2 })
11
+ assert File.exists? TESTMONTAGE
12
+ assert dimensions(TESTMONTAGE) == ["104", "78", nil]
13
+ end
14
+ should "generate a single 3 column (90x120) montage from 12 22px images with 4 pixel borders" do
15
+ Allthumbs.generate(IMAGES, TESTMONTAGE, { :column => 3, :border => 4 })
16
+ assert File.exists? TESTMONTAGE
17
+ assert dimensions(TESTMONTAGE) == ["90", "120", nil]
18
+ end
19
+ should "raise an exception when bad image files are passed" do
20
+ assert_raise RuntimeError do
21
+ Allthumbs.generate('some/nonexistent/file.jpg', TESTMONTAGE, { :column => 3, :border => 4 })
22
+ end
23
+ end
24
+ should "raise an exception when bad column row values are passed" do
25
+ assert_raise RuntimeError do
26
+ Allthumbs.generate(IMAGES, TESTMONTAGE, { :column => 3, :row => 20, :border => 4 })
27
+ end
28
+ end
29
+ end
30
+
31
+ def dimensions file
32
+ file = file.path if file.respond_to? "path"
33
+ geometry = begin
34
+ Cocaine::CommandLine.new("identify", "-format %wx%h :file", :file => "#{file}[0]").run
35
+ rescue Cocaine::CommandNotFoundError => e
36
+ raise "Could not run the 'identify' command. Please install ImageMagick."
37
+ end
38
+ parse(geometry) || (raise "#{file} is not recognized by the 'identify' command.")
39
+ end
40
+
41
+ def parse string
42
+ if match = (string && string.match(/\b(\d*)x?(\d*)\b([\>\<\#\@\%^!])?/i))
43
+ return match[1,3]
44
+ end
45
+ end
46
+
@@ -0,0 +1,21 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'cocaine'
5
+
6
+ begin
7
+ require 'ruby-debug'
8
+ rescue LoadError => e
9
+ puts "debugger disabled"
10
+ end
11
+
12
+ ROOT = File.join(File.dirname(__FILE__), '..')
13
+ $LOAD_PATH << File.join(ROOT, 'lib')
14
+ $LOAD_PATH << File.join(ROOT, 'lib', 'allthumbs')
15
+
16
+ require File.join(ROOT, 'lib', 'allthumbs.rb')
17
+
18
+ FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures")
19
+
20
+ IMAGES = Dir::glob('test/images/*jpg').map { |f| f }.join(' ')
21
+ TESTMONTAGE = 'test/tmp-montage.jpg'
Binary file
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: allthumbs
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - John Bresnik
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-06-20 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: shoulda
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :development
33
+ version_requirements: *id001
34
+ description: Generate single image from tons of thumbails
35
+ email: jbresnik@barbariangroup.com
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files:
41
+ - README.rdoc
42
+ files:
43
+ - README.rdoc
44
+ - LICENSE
45
+ - Rakefile
46
+ - init.rb
47
+ - lib/allthumbs/version.rb
48
+ - lib/allthumbs.rb
49
+ - lib/tasks/allthumbs.rake
50
+ - test/allthumbs_test.rb
51
+ - test/helper.rb
52
+ - test/images/00_avatar_tiny.jpg
53
+ - test/images/bnjmn_red_hotel_tiny.jpg
54
+ - test/images/hunter2_tiny.jpg
55
+ - test/images/hunter_tiny.jpg
56
+ - test/images/image1_tiny.jpg
57
+ - test/images/lexy1_tiny.jpg
58
+ - test/images/mypictr_last.fm_tiny.jpg
59
+ - test/images/Photo_1_tiny.jpg
60
+ - test/images/Photo_26_tiny.jpg
61
+ - test/images/Photo_61_tiny.jpg
62
+ - test/images/shelby_tiny.jpg
63
+ - test/images/tbgmixer_fedora_tiny.jpg
64
+ - test/tmp-montage.jpg
65
+ homepage: https://github.com/brez/allthumbs
66
+ licenses: []
67
+
68
+ post_install_message:
69
+ rdoc_options:
70
+ - --line-numbers
71
+ - --inline-source
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ hash: 3
80
+ segments:
81
+ - 0
82
+ version: "0"
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ hash: 3
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ requirements:
93
+ - ImageMagick
94
+ rubyforge_project:
95
+ rubygems_version: 1.8.5
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: Generate single image from tons of thumbails
99
+ test_files: []
100
+