gallerize 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/gallerize +1 -1
- data/lib/gallerizer.rb +10 -31
- data/lib/image.rb +38 -0
- data/themes/default/index.html.erb +2 -2
- data/themes/default/resources/screen.css +6 -1
- data/themes/default/show.html.erb +3 -3
- metadata +4 -3
data/bin/gallerize
CHANGED
data/lib/gallerizer.rb
CHANGED
@@ -3,6 +3,7 @@ require 'fileutils'
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'rmagick'
|
5
5
|
require 'natural_sort_kernel'
|
6
|
+
require File.join(File.dirname(__FILE__), 'image')
|
6
7
|
|
7
8
|
class Gallerizer
|
8
9
|
include FileUtils
|
@@ -12,34 +13,8 @@ class Gallerizer
|
|
12
13
|
@output_path = output_path
|
13
14
|
@theme_path = File.join(File.dirname(__FILE__), "..", "themes", theme)
|
14
15
|
end
|
15
|
-
|
16
|
-
def resize(image, size, square = false)
|
17
|
-
thumb_file_path = File.join(@output_path, "thumbs", File.basename(image, ".jpg") << "_#{size}.jpg")
|
18
16
|
|
19
|
-
|
20
|
-
file = Magick::Image::read(image).first
|
21
|
-
|
22
|
-
if square
|
23
|
-
file.resize_to_fill!(size, size)
|
24
|
-
else
|
25
|
-
file.resize_to_fit!(size, size)
|
26
|
-
end
|
27
|
-
|
28
|
-
file.write(thumb_file_path){ self.quality = (size <= 250 ? 70 : 95) }
|
29
|
-
end
|
30
|
-
|
31
|
-
File.basename(thumb_file_path)
|
32
|
-
end
|
33
|
-
|
34
|
-
def next_image(i)
|
35
|
-
@images.size - 1 != i ? @images[i + 1] : nil
|
36
|
-
end
|
37
|
-
|
38
|
-
def previous_image(i)
|
39
|
-
i != 0 ? @images[i - 1] : nil
|
40
|
-
end
|
41
|
-
|
42
|
-
def generate
|
17
|
+
def gallerize
|
43
18
|
# Create necessary output paths
|
44
19
|
mkdir_p([@output_path, File.join(@output_path, "thumbs"), File.join(@output_path, "show"), File.join(@output_path, "resources")])
|
45
20
|
|
@@ -47,8 +22,9 @@ class Gallerizer
|
|
47
22
|
cp_r(File.join(@theme_path, "resources/."), File.join(@output_path, "resources"))
|
48
23
|
|
49
24
|
# Gather images
|
50
|
-
|
51
|
-
|
25
|
+
image_paths = Dir["*.jpg"].natural_sort
|
26
|
+
@images = image_paths.collect { |image_path| Image.new(image_paths.index(image_path), File.expand_path(image_path), @output_path) }
|
27
|
+
|
52
28
|
# Load templates
|
53
29
|
index_template = ERB.new(File.open(File.join(@theme_path, "index.html.erb")) { |f| f.read })
|
54
30
|
show_template = ERB.new(File.open(File.join(@theme_path, "show.html.erb")) { |f| f.read })
|
@@ -57,8 +33,11 @@ class Gallerizer
|
|
57
33
|
File.open(File.join(@output_path, "index.html"), "w") { |f| f.write(index_template.result(binding)) }
|
58
34
|
|
59
35
|
# Create show pages
|
60
|
-
@images.
|
61
|
-
|
36
|
+
@images.each do |image|
|
37
|
+
previous_image = (image.id != 0 ? @images[image.id - 1] : nil)
|
38
|
+
next_image = (@images.size - 1 != image.id ? @images[image.id + 1] : nil)
|
39
|
+
|
40
|
+
File.open(File.join(@output_path, "show", "#{image.id}.html"), "w") { |f| f.write(show_template.result(binding)) }
|
62
41
|
end
|
63
42
|
end
|
64
43
|
end
|
data/lib/image.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
class Image
|
2
|
+
attr_reader :id, :path
|
3
|
+
|
4
|
+
def initialize(id, path, output_path)
|
5
|
+
@id = id
|
6
|
+
@path = path
|
7
|
+
@output_path = output_path
|
8
|
+
end
|
9
|
+
|
10
|
+
def basename
|
11
|
+
File.basename(@path)
|
12
|
+
end
|
13
|
+
|
14
|
+
def resize(size, square = false)
|
15
|
+
thumb_file_path = File.join(@output_path, "thumbs", File.basename(@path, ".jpg") << "_#{size}.jpg")
|
16
|
+
|
17
|
+
unless File.exists?(thumb_file_path)
|
18
|
+
file = Magick::Image::read(@path).first
|
19
|
+
|
20
|
+
if square
|
21
|
+
file.resize_to_fill!(size, size)
|
22
|
+
else
|
23
|
+
file.resize_to_fit!(size, size)
|
24
|
+
end
|
25
|
+
|
26
|
+
file.write(thumb_file_path){ self.quality = (size <= 200 ? 75 : 95) }
|
27
|
+
|
28
|
+
# Free memory
|
29
|
+
file.destroy!
|
30
|
+
end
|
31
|
+
|
32
|
+
File.join("thumbs", File.basename(thumb_file_path))
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_s
|
36
|
+
basename
|
37
|
+
end
|
38
|
+
end
|
@@ -15,8 +15,8 @@
|
|
15
15
|
<h1><%= @name %></h1>
|
16
16
|
</header>
|
17
17
|
<section class="yui-cssbase">
|
18
|
-
<% @images.
|
19
|
-
<div class="item"><a href="show/<%=
|
18
|
+
<% @images.each do |image| %>
|
19
|
+
<div class="item"><a href="show/<%= image.id %>.html"><img src="<%= image.resize(150, true) %>" height="150" width="150" /></a></div>
|
20
20
|
<% end %>
|
21
21
|
</section>
|
22
22
|
</div>
|
@@ -13,6 +13,11 @@ body {
|
|
13
13
|
padding: 2em;
|
14
14
|
}
|
15
15
|
|
16
|
+
#container {
|
17
|
+
margin: 0 auto;
|
18
|
+
width: 675px;
|
19
|
+
}
|
20
|
+
|
16
21
|
h1 {
|
17
22
|
color: #777;
|
18
23
|
font-size: 400%;
|
@@ -22,7 +27,7 @@ h1 {
|
|
22
27
|
|
23
28
|
.item {
|
24
29
|
float: left;
|
25
|
-
margin: 0
|
30
|
+
margin: 0 15px 15px 0;
|
26
31
|
}
|
27
32
|
|
28
33
|
.item img {
|
@@ -15,9 +15,9 @@
|
|
15
15
|
<h1><%= @name %></h1>
|
16
16
|
</header>
|
17
17
|
<section class="yui-cssbase">
|
18
|
-
<img src="
|
19
|
-
<% if previous_image
|
20
|
-
<% if next_image
|
18
|
+
<img src="../<%= image.resize(675) %>" />
|
19
|
+
<% if previous_image %><a href="<%= previous_image.id %>.html"><img src="../<%= previous_image.resize(75, true)%>" /></a><% end %>
|
20
|
+
<% if next_image %><a href="<%= next_image.id %>.html"><img src="../<%= next_image.resize(75, true)%>" /></a><% end %>
|
21
21
|
</section>
|
22
22
|
</div>
|
23
23
|
</body>
|
metadata
CHANGED
@@ -4,8 +4,8 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
version: "0.
|
7
|
+
- 2
|
8
|
+
version: "0.2"
|
9
9
|
platform: ruby
|
10
10
|
authors:
|
11
11
|
- Nick Chapman
|
@@ -67,8 +67,9 @@ extensions: []
|
|
67
67
|
extra_rdoc_files: []
|
68
68
|
|
69
69
|
files:
|
70
|
-
- lib/gallerizer.rb
|
71
70
|
- bin/gallerize
|
71
|
+
- lib/gallerizer.rb
|
72
|
+
- lib/image.rb
|
72
73
|
- themes/default/index.html.erb
|
73
74
|
- themes/default/resources/screen.css
|
74
75
|
- themes/default/show.html.erb
|