lash-sprites 0.3.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/.gitignore +2 -0
- data/Gemfile +4 -0
- data/LICENSE +165 -0
- data/README +38 -0
- data/Rakefile +38 -0
- data/examples/css/css.rb +17 -0
- data/examples/css/css_cli.rb +29 -0
- data/examples/example_imgs/1.png +0 -0
- data/examples/example_imgs/10.png +0 -0
- data/examples/example_imgs/11.png +0 -0
- data/examples/example_imgs/12.png +0 -0
- data/examples/example_imgs/13.png +0 -0
- data/examples/example_imgs/14.png +0 -0
- data/examples/example_imgs/15.png +0 -0
- data/examples/example_imgs/16.png +0 -0
- data/examples/example_imgs/17.png +0 -0
- data/examples/example_imgs/18.png +0 -0
- data/examples/example_imgs/19.png +0 -0
- data/examples/example_imgs/2.png +0 -0
- data/examples/example_imgs/20.png +0 -0
- data/examples/example_imgs/21.png +0 -0
- data/examples/example_imgs/22.png +0 -0
- data/examples/example_imgs/23.png +0 -0
- data/examples/example_imgs/24.png +0 -0
- data/examples/example_imgs/25.png +0 -0
- data/examples/example_imgs/26.png +0 -0
- data/examples/example_imgs/27.png +0 -0
- data/examples/example_imgs/28.png +0 -0
- data/examples/example_imgs/29.png +0 -0
- data/examples/example_imgs/3.png +0 -0
- data/examples/example_imgs/30.png +0 -0
- data/examples/example_imgs/31.png +0 -0
- data/examples/example_imgs/32.png +0 -0
- data/examples/example_imgs/33.png +0 -0
- data/examples/example_imgs/34.png +0 -0
- data/examples/example_imgs/35.png +0 -0
- data/examples/example_imgs/36.png +0 -0
- data/examples/example_imgs/37.png +0 -0
- data/examples/example_imgs/38.png +0 -0
- data/examples/example_imgs/39.png +0 -0
- data/examples/example_imgs/4.png +0 -0
- data/examples/example_imgs/40.png +0 -0
- data/examples/example_imgs/41.png +0 -0
- data/examples/example_imgs/42.png +0 -0
- data/examples/example_imgs/43.png +0 -0
- data/examples/example_imgs/44.png +0 -0
- data/examples/example_imgs/45.png +0 -0
- data/examples/example_imgs/46.png +0 -0
- data/examples/example_imgs/47.png +0 -0
- data/examples/example_imgs/48.png +0 -0
- data/examples/example_imgs/49.png +0 -0
- data/examples/example_imgs/5.png +0 -0
- data/examples/example_imgs/50.png +0 -0
- data/examples/example_imgs/51.png +0 -0
- data/examples/example_imgs/52.png +0 -0
- data/examples/example_imgs/53.png +0 -0
- data/examples/example_imgs/54.png +0 -0
- data/examples/example_imgs/55.png +0 -0
- data/examples/example_imgs/56.png +0 -0
- data/examples/example_imgs/57.png +0 -0
- data/examples/example_imgs/58.png +0 -0
- data/examples/example_imgs/59.png +0 -0
- data/examples/example_imgs/6.png +0 -0
- data/examples/example_imgs/60.png +0 -0
- data/examples/example_imgs/7.png +0 -0
- data/examples/example_imgs/8.png +0 -0
- data/examples/example_imgs/9.png +0 -0
- data/examples/packing/packing.rb +19 -0
- data/lash-sprites.gemspec +21 -0
- data/lib/.DS_Store +0 -0
- data/lib/lash-sprites/.DS_Store +0 -0
- data/lib/lash-sprites/block.rb +34 -0
- data/lib/lash-sprites/css.rb +27 -0
- data/lib/lash-sprites/graphics_manager/gd2.rb +43 -0
- data/lib/lash-sprites/graphics_manager/graphics_manager.rb +22 -0
- data/lib/lash-sprites/graphics_manager/rmagick.rb +45 -0
- data/lib/lash-sprites/image.rb +46 -0
- data/lib/lash-sprites/packer/both_smart.rb +90 -0
- data/lib/lash-sprites/packer/both_split.rb +171 -0
- data/lib/lash-sprites/packer/even.rb +78 -0
- data/lib/lash-sprites/packer/horizontal_smart.rb +72 -0
- data/lib/lash-sprites/packer/horizontal_split.rb +156 -0
- data/lib/lash-sprites/packer/horizontal_stack.rb +22 -0
- data/lib/lash-sprites/packer/ratio.rb +94 -0
- data/lib/lash-sprites/packer/vertical_smart.rb +72 -0
- data/lib/lash-sprites/packer/vertical_split.rb +164 -0
- data/lib/lash-sprites/packer/vertical_stack.rb +23 -0
- data/lib/lash-sprites/sprite.rb +272 -0
- data/lib/lash-sprites/version.rb +5 -0
- data/test/b_graphics.rb +37 -0
- data/test/b_packers.rb +53 -0
- data/test/imgs/1.png +0 -0
- data/test/imgs/10.png +0 -0
- data/test/imgs/11.png +0 -0
- data/test/imgs/12.png +0 -0
- data/test/imgs/13.png +0 -0
- data/test/imgs/14.png +0 -0
- data/test/imgs/15.png +0 -0
- data/test/imgs/16.png +0 -0
- data/test/imgs/17.png +0 -0
- data/test/imgs/18.png +0 -0
- data/test/imgs/19.png +0 -0
- data/test/imgs/2.png +0 -0
- data/test/imgs/20.png +0 -0
- data/test/imgs/21.png +0 -0
- data/test/imgs/22.png +0 -0
- data/test/imgs/23.png +0 -0
- data/test/imgs/24.png +0 -0
- data/test/imgs/25.png +0 -0
- data/test/imgs/26.png +0 -0
- data/test/imgs/27.png +0 -0
- data/test/imgs/28.png +0 -0
- data/test/imgs/29.png +0 -0
- data/test/imgs/3.png +0 -0
- data/test/imgs/30.png +0 -0
- data/test/imgs/31.png +0 -0
- data/test/imgs/32.png +0 -0
- data/test/imgs/33.png +0 -0
- data/test/imgs/34.png +0 -0
- data/test/imgs/35.png +0 -0
- data/test/imgs/36.png +0 -0
- data/test/imgs/37.png +0 -0
- data/test/imgs/38.png +0 -0
- data/test/imgs/39.png +0 -0
- data/test/imgs/4.png +0 -0
- data/test/imgs/40.png +0 -0
- data/test/imgs/41.png +0 -0
- data/test/imgs/42.png +0 -0
- data/test/imgs/43.png +0 -0
- data/test/imgs/44.png +0 -0
- data/test/imgs/45.png +0 -0
- data/test/imgs/46.png +0 -0
- data/test/imgs/47.png +0 -0
- data/test/imgs/48.png +0 -0
- data/test/imgs/49.png +0 -0
- data/test/imgs/5.png +0 -0
- data/test/imgs/50.png +0 -0
- data/test/imgs/51.png +0 -0
- data/test/imgs/52.png +0 -0
- data/test/imgs/53.png +0 -0
- data/test/imgs/54.png +0 -0
- data/test/imgs/55.png +0 -0
- data/test/imgs/56.png +0 -0
- data/test/imgs/57.png +0 -0
- data/test/imgs/58.png +0 -0
- data/test/imgs/59.png +0 -0
- data/test/imgs/6.png +0 -0
- data/test/imgs/60.png +0 -0
- data/test/imgs/7.png +0 -0
- data/test/imgs/8.png +0 -0
- data/test/imgs/9.png +0 -0
- data/test/t_gd2.rb +28 -0
- data/test/t_generic.rb +183 -0
- data/test/t_rmagick.rb +29 -0
- metadata +269 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
2
|
+
Version 3, 29 June 2007
|
3
|
+
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
6
|
+
of this license document, but changing it is not allowed.
|
7
|
+
|
8
|
+
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
11
|
+
License, supplemented by the additional permissions listed below.
|
12
|
+
|
13
|
+
0. Additional Definitions.
|
14
|
+
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
17
|
+
General Public License.
|
18
|
+
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
20
|
+
other than an Application or a Combined Work as defined below.
|
21
|
+
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
25
|
+
of using an interface provided by the Library.
|
26
|
+
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
28
|
+
Application with the Library. The particular version of the Library
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
30
|
+
Version".
|
31
|
+
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
35
|
+
based on the Application, and not on the Linked Version.
|
36
|
+
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
38
|
+
object code and/or source code for the Application, including any data
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
41
|
+
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
43
|
+
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
46
|
+
|
47
|
+
2. Conveying Modified Versions.
|
48
|
+
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
51
|
+
that uses the facility (other than as an argument passed when the
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
53
|
+
version:
|
54
|
+
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
56
|
+
ensure that, in the event an Application does not supply the
|
57
|
+
function or data, the facility still operates, and performs
|
58
|
+
whatever part of its purpose remains meaningful, or
|
59
|
+
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
61
|
+
this License applicable to that copy.
|
62
|
+
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
64
|
+
|
65
|
+
The object code form of an Application may incorporate material from
|
66
|
+
a header file that is part of the Library. You may convey such object
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
68
|
+
material is not limited to numerical parameters, data structure
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
71
|
+
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
73
|
+
Library is used in it and that the Library and its use are
|
74
|
+
covered by this License.
|
75
|
+
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
77
|
+
document.
|
78
|
+
|
79
|
+
4. Combined Works.
|
80
|
+
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
82
|
+
taken together, effectively do not restrict modification of the
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
85
|
+
the following:
|
86
|
+
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
88
|
+
the Library is used in it and that the Library and its use are
|
89
|
+
covered by this License.
|
90
|
+
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
92
|
+
document.
|
93
|
+
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
95
|
+
execution, include the copyright notice for the Library among
|
96
|
+
these notices, as well as a reference directing the user to the
|
97
|
+
copies of the GNU GPL and this license document.
|
98
|
+
|
99
|
+
d) Do one of the following:
|
100
|
+
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
102
|
+
License, and the Corresponding Application Code in a form
|
103
|
+
suitable for, and under terms that permit, the user to
|
104
|
+
recombine or relink the Application with a modified version of
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
107
|
+
Corresponding Source.
|
108
|
+
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
111
|
+
a copy of the Library already present on the user's computer
|
112
|
+
system, and (b) will operate properly with a modified version
|
113
|
+
of the Library that is interface-compatible with the Linked
|
114
|
+
Version.
|
115
|
+
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
117
|
+
be required to provide such information under section 6 of the
|
118
|
+
GNU GPL, and only to the extent that such information is
|
119
|
+
necessary to install and execute a modified version of the
|
120
|
+
Combined Work produced by recombining or relinking the
|
121
|
+
Application with a modified version of the Linked Version. (If
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
126
|
+
for conveying Corresponding Source.)
|
127
|
+
|
128
|
+
5. Combined Libraries.
|
129
|
+
|
130
|
+
You may place library facilities that are a work based on the
|
131
|
+
Library side by side in a single library together with other library
|
132
|
+
facilities that are not Applications and are not covered by this
|
133
|
+
License, and convey such a combined library under terms of your
|
134
|
+
choice, if you do both of the following:
|
135
|
+
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
137
|
+
on the Library, uncombined with any other library facilities,
|
138
|
+
conveyed under the terms of this License.
|
139
|
+
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
141
|
+
is a work based on the Library, and explaining where to find the
|
142
|
+
accompanying uncombined form of the same work.
|
143
|
+
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
145
|
+
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
148
|
+
versions will be similar in spirit to the present version, but may
|
149
|
+
differ in detail to address new problems or concerns.
|
150
|
+
|
151
|
+
Each version is given a distinguishing version number. If the
|
152
|
+
Library as you received it specifies that a certain numbered version
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
154
|
+
applies to it, you have the option of following the terms and
|
155
|
+
conditions either of that published version or of any later version
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
160
|
+
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
164
|
+
permanent authorization for you to choose that version for the
|
165
|
+
Library.
|
data/README
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
Originally forked from https://github.com/ckwalsh/RubySprites
|
2
|
+
|
3
|
+
|
4
|
+
= RubySprites
|
5
|
+
|
6
|
+
Provides a library for generating image sprites from multiple images, as
|
7
|
+
well as a few basic tools to manage sprites and act as example
|
8
|
+
implementations.
|
9
|
+
|
10
|
+
== Dependencies
|
11
|
+
|
12
|
+
Gems
|
13
|
+
* RMagick 2.x.x OR
|
14
|
+
* GD2
|
15
|
+
|
16
|
+
== Special Thanks
|
17
|
+
|
18
|
+
Special thanks to the team at WhitePages.com. This module was invisioned
|
19
|
+
and developed during my internship there, and would not be what it is
|
20
|
+
today without their help.
|
21
|
+
|
22
|
+
== License
|
23
|
+
|
24
|
+
RubySprites Copyright (c) 2009 Cullen Walsh
|
25
|
+
GNU Lesser General Public License
|
26
|
+
|
27
|
+
RubySprites is free software: you can redistribute it and/or modify
|
28
|
+
it under the terms of the GNU Lesser General Public License as
|
29
|
+
published by the Free Software Foundation, either version 3 of the
|
30
|
+
License, or (at your option) any later version.
|
31
|
+
|
32
|
+
RubySprites is distributed in the hope that it will be useful,
|
33
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
34
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
35
|
+
GNU Lesser General Public License for more details.
|
36
|
+
|
37
|
+
You should have received a copy of the GNU Lesser General Public License
|
38
|
+
along with RubySprites. If not, see <http://www.gnu.org/licenses/>.
|
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
|
6
|
+
desc 'Determine server compatibility and test components'
|
7
|
+
task :test do
|
8
|
+
$:.unshift 'lib'
|
9
|
+
require 'ruby_sprites/sprite'
|
10
|
+
|
11
|
+
puts 'Availible Image Managers'
|
12
|
+
RubySprites::Sprite.graphics_managers.values.each { |x|
|
13
|
+
puts "\t#{x.const_get(:DESCRIPTION)}"
|
14
|
+
}
|
15
|
+
|
16
|
+
puts 'Availible packing algorithms'
|
17
|
+
Dir.entries('lib/ruby_sprites/packer').sort.each { |x|
|
18
|
+
next unless x.match(/\.rb$/)
|
19
|
+
class_name = x.gsub('.rb', '').capitalize.gsub(/_([a-z]+)/) {|x| $1.capitalize}
|
20
|
+
puts "\t#{class_name}"
|
21
|
+
}
|
22
|
+
|
23
|
+
puts ""
|
24
|
+
|
25
|
+
require 'test/t_rmagick'
|
26
|
+
require 'test/t_gd2'
|
27
|
+
puts ""
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
desc 'Benchmark availible graphics backends and packing algorithms'
|
32
|
+
task :benchmark do
|
33
|
+
puts "== Benchmarking Graphics Engines =="
|
34
|
+
require 'test/b_graphics'
|
35
|
+
puts "== Benchmarking Packing algorithms =="
|
36
|
+
require 'test/b_packers'
|
37
|
+
end
|
38
|
+
|
data/examples/css/css.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
current_dir = File.dirname(__FILE__)
|
2
|
+
|
3
|
+
$:.unshift File.join(current_dir, '../../lib')
|
4
|
+
|
5
|
+
require 'ruby_sprites/sprite'
|
6
|
+
require 'ruby_sprites/css'
|
7
|
+
|
8
|
+
sprite = RubySprites::Sprite.new('css/sprite.png', current_dir + '/..')
|
9
|
+
|
10
|
+
(1..60).each do |x|
|
11
|
+
sprite.add_image("example_imgs/#{x}.png")
|
12
|
+
end
|
13
|
+
|
14
|
+
sprite.update
|
15
|
+
|
16
|
+
puts RubySprites::CSS.generate(sprite)
|
17
|
+
RubySprites::CSS.generate(sprite, 'css/css.css')
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
current_dir = File.dirname(__FILE__)
|
4
|
+
$:.unshift File.join(current_dir, '../../lib')
|
5
|
+
|
6
|
+
require 'ruby_sprites/sprite'
|
7
|
+
require 'ruby_sprites/css'
|
8
|
+
|
9
|
+
if ARGV.length < 3
|
10
|
+
puts "Usage: ruby css_cli.rb repeat-type sprite_image.ext img1.ext [img2.ext] [...]"
|
11
|
+
puts "repeat-type may be 'default', 'vertical', or 'horizontal'"
|
12
|
+
puts "sprite_image.ext is the output sprite file"
|
13
|
+
exit
|
14
|
+
end
|
15
|
+
|
16
|
+
repeat = ARGV.shift
|
17
|
+
sp_file = ARGV.shift
|
18
|
+
|
19
|
+
options = {
|
20
|
+
:repeat => (repeat == 'default') ? false : repeat.to_sym,
|
21
|
+
}
|
22
|
+
|
23
|
+
sprite = RubySprites::Sprite.new(sp_file, '.', options)
|
24
|
+
|
25
|
+
sprite.add_images(ARGV)
|
26
|
+
|
27
|
+
sprite.update
|
28
|
+
|
29
|
+
RubySprites::CSS.generate(sprite, "#{sp_file}.css")
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,19 @@
|
|
1
|
+
current_dir = File.dirname(__FILE__)
|
2
|
+
|
3
|
+
$:.unshift File.join(current_dir, '../../lib')
|
4
|
+
|
5
|
+
require 'ruby_sprites/sprite'
|
6
|
+
|
7
|
+
|
8
|
+
pack_types = [:vertical_stack, :horizontal_stack, :vertical_smart, :horizontal_smart, :both_smart, :even, :ratio, :both_split, :vertical_split, :horizontal_split]
|
9
|
+
|
10
|
+
pack_types = [:both_smart, :both_split, :vertical_split, :horizontal_split]
|
11
|
+
|
12
|
+
pack_types.each do |pack|
|
13
|
+
sprite = RubySprites::Sprite.new("packing/#{pack.to_s}.png", current_dir + '/..', {:pack_type => pack, :force_update => true})
|
14
|
+
(1..60).each do |x|
|
15
|
+
sprite.add_image("example_imgs/#{x}.png")
|
16
|
+
end
|
17
|
+
|
18
|
+
sprite.update
|
19
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "lash-sprites/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "lash-sprites"
|
7
|
+
s.version = Lash::Sprites::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Cullen Walsh", "Paul Alexander"]
|
10
|
+
s.email = ["gems@appsinyourpants.com"]
|
11
|
+
s.homepage = "https://github.com/appsinyourpants/lash-sprites"
|
12
|
+
s.summary = 'A library to ease the dynamic generation of CSS spritesfrom a list of images or a css file. Supports multiple image libraries, including GD2 and ImageMagick, and multiple different packing algorithms.'
|
13
|
+
|
14
|
+
s.rubyforge_project = "lash-sprites"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
end
|
data/lib/.DS_Store
ADDED
Binary file
|
Binary file
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module RubySprites
|
2
|
+
class Block
|
3
|
+
|
4
|
+
attr_reader :x, :y, :width, :height
|
5
|
+
|
6
|
+
def initialize(x, y, width, height)
|
7
|
+
@x = x
|
8
|
+
@y = y
|
9
|
+
@width = width
|
10
|
+
@height = height
|
11
|
+
end
|
12
|
+
|
13
|
+
def fits?(img)
|
14
|
+
return img.width <= @width && img.height <= @height
|
15
|
+
end
|
16
|
+
|
17
|
+
def split(img)
|
18
|
+
blocks = []
|
19
|
+
if (@width - img.width) * img.height > (@height - img.height) * img.width
|
20
|
+
blocks.push Block.new(@x + img.width, @y, @width - img.width, @height) if @width != img.width
|
21
|
+
blocks.push Block.new(@x, @y + img.height, img.width, @height - img.height) if @height != img.height
|
22
|
+
else
|
23
|
+
blocks.push Block.new(@x + img.width, @y, @width - img.width, img.height) if @width != img.width
|
24
|
+
blocks.push Block.new(@x, @y + img.height, @width, @height - img.height) if @height != img.height
|
25
|
+
end
|
26
|
+
return blocks
|
27
|
+
end
|
28
|
+
|
29
|
+
def area
|
30
|
+
@area = @width * @height if @area.nil?
|
31
|
+
return @area
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'ruby_sprites/sprite'
|
2
|
+
|
3
|
+
module RubySprites
|
4
|
+
class CSS
|
5
|
+
|
6
|
+
def self.generate(sprite, file = nil)
|
7
|
+
css = ''
|
8
|
+
css_template = ".%s {
|
9
|
+
background: url(%s) %dpx %dpx no-repeat;
|
10
|
+
height: %dpx;
|
11
|
+
width: %dpx;
|
12
|
+
}\n\n"
|
13
|
+
sprite.images.each do |path, image|
|
14
|
+
class_name = path[0,path.rindex('.')].gsub('/','_')
|
15
|
+
css += sprintf(css_template, class_name, sprite.filename, -image.x, -image.y, image.height, image.width)
|
16
|
+
end
|
17
|
+
|
18
|
+
if file.nil?
|
19
|
+
return css
|
20
|
+
else
|
21
|
+
fp = File.open(sprite.file_root + file, 'w')
|
22
|
+
fp.write(css)
|
23
|
+
fp.close
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'ruby_sprites/graphics_manager/graphics_manager'
|
2
|
+
|
3
|
+
module RubySprites
|
4
|
+
module GraphicsManager
|
5
|
+
class Gd2 < GraphicsManager
|
6
|
+
|
7
|
+
DESCRIPTION = 'GD2'
|
8
|
+
|
9
|
+
def self.availible?
|
10
|
+
begin
|
11
|
+
require 'rubygems'
|
12
|
+
require 'gd2'
|
13
|
+
rescue LoadError
|
14
|
+
return false
|
15
|
+
end
|
16
|
+
|
17
|
+
return true
|
18
|
+
end
|
19
|
+
|
20
|
+
def combine(images, width, height)
|
21
|
+
image = GD2::Image.new(width, height)
|
22
|
+
images.each do |path, img|
|
23
|
+
next unless img.exists?
|
24
|
+
i = GD2::Image.import(@sprite.file_root + path)
|
25
|
+
w = width - img.x
|
26
|
+
w = img.width if img.width < w
|
27
|
+
h = height - img.y
|
28
|
+
h = img.height if img.height < h
|
29
|
+
image.copy_from(i, img.x, img.y, 0, 0, w, h)
|
30
|
+
i = nil
|
31
|
+
end
|
32
|
+
image.export(@sprite.image_file)
|
33
|
+
end
|
34
|
+
|
35
|
+
def get_info(path)
|
36
|
+
img = GD2::Image.import(@sprite.file_root + path)
|
37
|
+
info = {:width => img.width, :height => img.height}
|
38
|
+
img = nil
|
39
|
+
return info
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module RubySprites
|
2
|
+
module GraphicsManager
|
3
|
+
class GraphicsManager
|
4
|
+
|
5
|
+
def initialize(sprite)
|
6
|
+
@sprite = sprite
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.availible?
|
10
|
+
return false
|
11
|
+
end
|
12
|
+
|
13
|
+
def combine(images, width, height)
|
14
|
+
raise "Must be overridden"
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_info(image)
|
18
|
+
raise "Must be overridden"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|