picturama 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +22 -0
- data/LICENCE +50 -0
- data/README.md +43 -0
- data/config/config.sample.yml +5 -0
- data/i18n/en.yml +11 -0
- data/i18n/es.yml +11 -0
- data/lib/ext/string.rb +15 -0
- data/lib/picturama.rb +27 -0
- data/lib/picturama/album.rb +72 -0
- data/lib/picturama/picture.rb +33 -0
- data/lib/picturama/version.rb +3 -0
- data/picturama.gemspec +20 -0
- data/rakefile +35 -0
- data/spec/album_spec.rb +34 -0
- data/spec/picture_spec.rb +26 -0
- data/spec/pictures/king.jpg +0 -0
- data/spec/pictures/quimby.gif +0 -0
- data/spec/pictures/vote-quimby.jpg +0 -0
- data/spec/pictures/vote_quimby.jpg +0 -0
- metadata +97 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.2.4)
|
5
|
+
mini_magick (3.6.0)
|
6
|
+
subexec (~> 0.2.1)
|
7
|
+
rspec (2.13.0)
|
8
|
+
rspec-core (~> 2.13.0)
|
9
|
+
rspec-expectations (~> 2.13.0)
|
10
|
+
rspec-mocks (~> 2.13.0)
|
11
|
+
rspec-core (2.13.1)
|
12
|
+
rspec-expectations (2.13.0)
|
13
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
14
|
+
rspec-mocks (2.13.1)
|
15
|
+
subexec (0.2.3)
|
16
|
+
|
17
|
+
PLATFORMS
|
18
|
+
ruby
|
19
|
+
|
20
|
+
DEPENDENCIES
|
21
|
+
mini_magick (~> 3.6.0)
|
22
|
+
rspec
|
data/LICENCE
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
Copyright (c) 2012 David Silveira
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any
|
4
|
+
person obtaining a copy of this software and associated
|
5
|
+
documentation files (the "Software"), to deal in the
|
6
|
+
Software without restriction, including without limitation
|
7
|
+
the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the
|
9
|
+
Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice
|
13
|
+
shall be included in all copies or substantial portions of
|
14
|
+
the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
|
17
|
+
KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
18
|
+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
19
|
+
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
20
|
+
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
21
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
22
|
+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
23
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
|
25
|
+
----------------------------------------------------------
|
26
|
+
|
27
|
+
TRADUCCIÓN NO OFICIAL NI AUTORIZADA PARA SU USO COMO LICENCIA LEGAL
|
28
|
+
Copyright (c) 2012 David Silveira
|
29
|
+
|
30
|
+
Se autoriza por la presente, de forma gratuita, a cualquier
|
31
|
+
persona que haya obtenido una copia de este software y
|
32
|
+
archivos asociados de documentación (el "Software"), para tratar en el
|
33
|
+
Software sin restricción, incluyendo sin ninguna limitación en lo que concierne
|
34
|
+
los derechos para usar, copiar, modificar, fusionar, publicar,
|
35
|
+
distribuir, sublicenciar, y / o vender copias de este
|
36
|
+
Software, y para permitir a las personas a las que se les proporcione el Software para
|
37
|
+
hacer lo mismo, sujeto a las siguientes condiciones:
|
38
|
+
|
39
|
+
El aviso de copyright anterior y este aviso de permiso
|
40
|
+
tendrá que ser incluido en todas las copias o partes sustanciales de
|
41
|
+
este Software.
|
42
|
+
|
43
|
+
EL SOFTWARE SE ENTREGA "TAL CUAL", SIN GARANTÍA DE NINGÚN
|
44
|
+
TIPO, EXPRESA O IMPLÍCITA, INCLUYENDO PERO SIN LIMITARSE A GARANTÍAS DE
|
45
|
+
MERCANTIBILIDAD, CAPACIDAD DE HACER Y DE NO INFRACCIÓN DE COPYRIGHT. EN NINGÚN
|
46
|
+
CASO LOS AUTORES O TITULARES DEL COPYRIGHT SERÁN RESPONSABLES DE
|
47
|
+
NINGUNA RECLAMACIÓN, DAÑOS U OTRAS RESPONSABILIDADES,
|
48
|
+
YA SEA EN UN LITIGIO, AGRAVIO O DE OTRO MODO,
|
49
|
+
DERIVADAS DE, OCASIONADAS POR CULPA DE O EN CONEXION CON EL
|
50
|
+
SOFTWARE O SU USO U OTRO TIPO DE ACCIONES EN EL SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Pictorama
|
2
|
+
|
3
|
+
Welcome to *Pictorama*. An easy picture gallery based on directory and files
|
4
|
+
|
5
|
+
### How to install
|
6
|
+
|
7
|
+
Just clone the github repo..
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
git clone git@github.com:aboyon/pictorama.git
|
11
|
+
```
|
12
|
+
### Configure your settings...
|
13
|
+
|
14
|
+
Copy the config.sample.yml to config.yml (into the config/ file)
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
cd config/
|
18
|
+
cp config.sample.yml config.yml
|
19
|
+
```
|
20
|
+
and then proceed to adjust the settings
|
21
|
+
|
22
|
+
```yaml
|
23
|
+
picturama:
|
24
|
+
album_source: '/home/user/Pictures/some_folder/'
|
25
|
+
allowed_formats: ['jpg','png','jpeg']
|
26
|
+
thumbnail_prefix: thumb_
|
27
|
+
thumnail_default_size: "200x200"
|
28
|
+
```
|
29
|
+
|
30
|
+
generate your thumbnails quickly, by using the rake task created for that
|
31
|
+
```
|
32
|
+
rake thumbnail:generate["/some/folder"] #you can specify a different folder...
|
33
|
+
```
|
34
|
+
and then you'll get an answer like this:
|
35
|
+
```
|
36
|
+
Generating 30 thumbnails for folder /some/folder/ ...
|
37
|
+
Size: 200x200
|
38
|
+
Thumbnail generated for source 1.JPG. Target destination thumb_1.JPG
|
39
|
+
Thumbnail generated for source 2.JPG. Target destination thumb_2.JPG
|
40
|
+
```
|
41
|
+
# License
|
42
|
+
|
43
|
+
Please [see licence file](https://github.com/aboyon/pictorama/blob/master/LICENCE) for further reading.
|
data/i18n/en.yml
ADDED
data/i18n/es.yml
ADDED
data/lib/ext/string.rb
ADDED
data/lib/picturama.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'picturama/album'
|
3
|
+
require 'picturama/picture'
|
4
|
+
require 'picturama/version'
|
5
|
+
|
6
|
+
module Picturama
|
7
|
+
|
8
|
+
Dir["lib/picturama/*.rb"].each { |file|
|
9
|
+
require "#{Dir.pwd}/#{file}"
|
10
|
+
}
|
11
|
+
|
12
|
+
def self.config
|
13
|
+
YAML.load_file('config/config.yml')['picturama']
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.albums(album_source)
|
17
|
+
albums = []
|
18
|
+
Dir["#{album_source}/*"].each { |album|
|
19
|
+
if File.directory?(album)
|
20
|
+
potential_album = Picturama::Album.new(:folder => album)
|
21
|
+
albums.push(album)
|
22
|
+
end
|
23
|
+
}
|
24
|
+
albums
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'picturama'
|
2
|
+
|
3
|
+
module Picturama
|
4
|
+
class Album
|
5
|
+
|
6
|
+
def initialize(args)
|
7
|
+
@folder = args[:folder]
|
8
|
+
@thumbnails = "#{args[:folder]}/thumbnails"
|
9
|
+
@resized = "#{args[:folder]}/resized"
|
10
|
+
end
|
11
|
+
|
12
|
+
def pictures(order = true)
|
13
|
+
if File.directory?(@folder)
|
14
|
+
list = []
|
15
|
+
filter = "#{@folder}/*.{#{Picturama::config['allowed_formats'].join(',')}}"
|
16
|
+
dir_list = generate_sorting(filter)
|
17
|
+
dir_list.each do |picture|
|
18
|
+
list.push(Picturama::Picture.new(picture))
|
19
|
+
end
|
20
|
+
unless order
|
21
|
+
list.reverse!
|
22
|
+
end
|
23
|
+
list
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def name
|
28
|
+
File.basename(@folder).humanize
|
29
|
+
end
|
30
|
+
|
31
|
+
def count_pictures
|
32
|
+
pictures.size
|
33
|
+
end
|
34
|
+
|
35
|
+
def has_thumbnails?
|
36
|
+
File.directory?(@thumbnails)
|
37
|
+
end
|
38
|
+
|
39
|
+
def has_resized?
|
40
|
+
File.directory?(@resized)
|
41
|
+
end
|
42
|
+
|
43
|
+
def has_broken_thumbnails?
|
44
|
+
thumbnails_found = Dir["#{@thumbnails}/*.{#{Picturama::config['allowed_formats'].join(',')}}"].size
|
45
|
+
!has_thumbnails? || thumbnails_found < count_pictures
|
46
|
+
end
|
47
|
+
|
48
|
+
def init_thumbnails
|
49
|
+
unless has_thumbnails?
|
50
|
+
FileUtils.mkdir_p "#{@thumbnails}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def init_resized
|
55
|
+
unless has_resized?
|
56
|
+
FileUtils.mkdir_p "#{@resized}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
protected
|
61
|
+
|
62
|
+
def generate_sorting(filter)
|
63
|
+
if (filter == :size)
|
64
|
+
dir_list = Dir[filter].sort_by{ |filename| File.size("#{filename}") }
|
65
|
+
else
|
66
|
+
dir_list = Dir[filter].sort_by{ |filename| File.ctime("#{filename}") }
|
67
|
+
end
|
68
|
+
dir_list
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'picturama'
|
2
|
+
|
3
|
+
module Picturama
|
4
|
+
class Picture < File
|
5
|
+
|
6
|
+
attr_accessor :thumbnail
|
7
|
+
|
8
|
+
def initialize(args)
|
9
|
+
super
|
10
|
+
@thumbnail = "#{File.dirname(path)}/thumbnails/#{Picturama::config['thumbnail_prefix']}#{File.basename(path)}"
|
11
|
+
@resized = "#{File.dirname(path)}/resized/resized_#{File.basename(path)}"
|
12
|
+
@metainfo = "#{File.dirname(path)}/resized/resized_#{File.basename(path)}.info"
|
13
|
+
end
|
14
|
+
|
15
|
+
def info
|
16
|
+
File.read(@metainfo) if File.exists?(@metainfo)
|
17
|
+
end
|
18
|
+
|
19
|
+
def has_resized?
|
20
|
+
File.exists?(@resized)
|
21
|
+
end
|
22
|
+
|
23
|
+
def has_thumbnail?
|
24
|
+
File.exists?(@thumbnail) && File.size(@thumbnail) < size
|
25
|
+
end
|
26
|
+
|
27
|
+
def remove_assoc
|
28
|
+
File.delete(@thumbnail) if has_thumbnail?
|
29
|
+
File.delete(@resized) if has_resized?
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
data/picturama.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
require "picturama/version"
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'picturama'
|
6
|
+
s.version = Picturama::VERSION
|
7
|
+
s.summary = "An easy picture gallery based on directory and files"
|
8
|
+
s.description = "An easy picture gallery based on directory and files"
|
9
|
+
s.authors = ["David Silveira"]
|
10
|
+
s.email = 'jdsilveira@gmail.com'
|
11
|
+
s.files = `git ls-files`.split("\n")
|
12
|
+
s.homepage = 'http://davidsilveira.me/picturama'
|
13
|
+
|
14
|
+
s.add_dependency('mini_magick', '~> 3.6.0')
|
15
|
+
|
16
|
+
s.add_development_dependency 'rspec'
|
17
|
+
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
end
|
data/rakefile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'picturama'
|
6
|
+
require 'mini_magick'
|
7
|
+
|
8
|
+
namespace :thumbnail do
|
9
|
+
|
10
|
+
desc "Generate thumbnail for a given folder or just a single file"
|
11
|
+
task :generate, :source do |t, args|
|
12
|
+
if File.directory?(args[:source]) || File.exists?(args[:source])
|
13
|
+
size = Picturama::config['thumnail_default_size']
|
14
|
+
album = Picturama::Album.new(:folder => args[:source])
|
15
|
+
puts "Generating #{album.count_pictures} thumbnails for folder #{args[:source]}..."
|
16
|
+
puts "Size: #{size}"
|
17
|
+
unless album.has_broken_thumbnails?
|
18
|
+
puts "WARNING: Seems that this album has all his thumbnails properly generated. There are no broken thumbs."
|
19
|
+
end
|
20
|
+
album.init_thumbnails
|
21
|
+
album.pictures.each do |picture|
|
22
|
+
unless picture.has_thumbnail?
|
23
|
+
thumb = MiniMagick::Image.open(picture.path)
|
24
|
+
thumb.resize "#{size}"
|
25
|
+
thumb.format "jpg"
|
26
|
+
thumb.write picture.thumbnail
|
27
|
+
puts "Thumbnail generated for source #{File.basename(picture.path)}. Target destination #{File.basename(picture.thumbnail)}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
else
|
31
|
+
puts "Error => target destination #{args[:source]} does not exist"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
data/spec/album_spec.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require_relative '../lib/picturama'
|
2
|
+
|
3
|
+
describe "For a given folder" do
|
4
|
+
|
5
|
+
before :each do
|
6
|
+
@target_exists_folder = "#{Dir.pwd}/spec/pictures"
|
7
|
+
@album = Picturama::Album.new(:folder => @target_exists_folder)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "check that Folder module return the list properly" do
|
11
|
+
expected_file = "#{@target_exists_folder}/king.jpg"
|
12
|
+
@album.pictures.first.class.should == Picturama::Picture.new('.').class
|
13
|
+
@album.pictures.first.path.should == expected_file
|
14
|
+
end
|
15
|
+
|
16
|
+
it "check thumnails for images" do
|
17
|
+
@album.pictures.first.has_thumbnail?.should be_false
|
18
|
+
@album.pictures.first.has_resized?.should be_false
|
19
|
+
end
|
20
|
+
|
21
|
+
it "check info for files" do
|
22
|
+
@album.pictures.first.info.nil?.should be_true
|
23
|
+
end
|
24
|
+
|
25
|
+
it "verify how many files are in album" do
|
26
|
+
@album.count_pictures.should > 0
|
27
|
+
end
|
28
|
+
|
29
|
+
it "gets all the albums in a given folder" do
|
30
|
+
Picturama::albums(File.dirname(@target_exists_folder)).size.should > 0
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'mini_magick'
|
2
|
+
require_relative '../lib/picturama'
|
3
|
+
|
4
|
+
describe "For a given picture in a given album" do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
@target_exists_folder = "#{Dir.pwd}/spec/pictures"
|
8
|
+
album = Picturama::Album.new(:folder => @target_exists_folder)
|
9
|
+
album.init_thumbnails
|
10
|
+
@picture = album.pictures.first
|
11
|
+
@thumb_w = 100
|
12
|
+
end
|
13
|
+
|
14
|
+
it "generate thumbnail" do
|
15
|
+
@picture.has_thumbnail?.should be_false
|
16
|
+
thumb = MiniMagick::Image.open(@picture.path)
|
17
|
+
thumb.resize "100x100"
|
18
|
+
thumb.format "jpg"
|
19
|
+
thumb.write @picture.thumbnail
|
20
|
+
@picture.has_thumbnail?.should be_true
|
21
|
+
@picture.remove_assoc
|
22
|
+
@picture.has_thumbnail?.should be_false
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: picturama
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- David Silveira
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: mini_magick
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.6.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.6.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: An easy picture gallery based on directory and files
|
47
|
+
email: jdsilveira@gmail.com
|
48
|
+
executables: []
|
49
|
+
extensions: []
|
50
|
+
extra_rdoc_files: []
|
51
|
+
files:
|
52
|
+
- .gitignore
|
53
|
+
- Gemfile
|
54
|
+
- Gemfile.lock
|
55
|
+
- LICENCE
|
56
|
+
- README.md
|
57
|
+
- config/config.sample.yml
|
58
|
+
- i18n/en.yml
|
59
|
+
- i18n/es.yml
|
60
|
+
- lib/ext/string.rb
|
61
|
+
- lib/picturama.rb
|
62
|
+
- lib/picturama/album.rb
|
63
|
+
- lib/picturama/picture.rb
|
64
|
+
- lib/picturama/version.rb
|
65
|
+
- picturama.gemspec
|
66
|
+
- rakefile
|
67
|
+
- spec/album_spec.rb
|
68
|
+
- spec/picture_spec.rb
|
69
|
+
- spec/pictures/king.jpg
|
70
|
+
- spec/pictures/quimby.gif
|
71
|
+
- spec/pictures/vote-quimby.jpg
|
72
|
+
- spec/pictures/vote_quimby.jpg
|
73
|
+
homepage: http://davidsilveira.me/picturama
|
74
|
+
licenses: []
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 1.8.24
|
94
|
+
signing_key:
|
95
|
+
specification_version: 3
|
96
|
+
summary: An easy picture gallery based on directory and files
|
97
|
+
test_files: []
|