sprite-factory 1.5.3 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+
3
+ #
4
+ # NOTE: rmagick dependencies include:
5
+ #
6
+ # $ sudo apt-get install imagemagick
7
+ # $ sudo apt-get install libmagickwand-dev
8
+
9
+ group :development do
10
+ gem "chunky_png", "1.3.0"
11
+ gem "rmagick", "2.13.2"
12
+ end
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011, 2012, 2013 Jake Gordon and contributors
1
+ Copyright (c) 2011, 2012, 2013, 2014 Jake Gordon and contributors
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- Sprite Factory (v1.5.3)
1
+ Sprite Factory (v1.6.0)
2
2
  =======================
3
3
 
4
4
  The sprite factory is a ruby library that can be used to generate
@@ -111,7 +111,7 @@ You can see the results of many of these options by viewing the sample page that
111
111
  comes with the gem in `test/images/reference/index.html`.
112
112
 
113
113
  >> NOTE: only the common options are available via the command line script (to keep it simple). Specifically,
114
- the advanced `width`, `height`, `padding`, `margin` and `nocss` options are only available via the Ruby interface.
114
+ the advanced `width`, `height`, and `nocss` options are only available via the Ruby interface.
115
115
 
116
116
  >> NOTE: the `width`, `height` and `padding` options are not particularly useful - you would be better off just
117
117
  making your source images have the correct dimensions by editing them appropriately in photoshop (or your editor of choice)
@@ -1,3 +1,10 @@
1
+ March 16th 2014 - v1.6.0
2
+ ------------------------
3
+
4
+ * Added raw ImageMagick driver can be used without RMagick gem (courtesy of @willglynn - Cheers!)
5
+ * Exposed `padding` and `margin` support to the cli interface (courtesy of @miguelgonz - Cheers!)
6
+
7
+
1
8
  February 21st 2013 - v1.5.3
2
9
  ---------------------------
3
10
  * bugfix: added back `:selector` when providing attributes for custom style generators (it was accidentally removed in v1.5.2)
data/bin/sf CHANGED
@@ -27,6 +27,8 @@ cssurl_help = "specify custom string to use for css image urls ( default:
27
27
  output_image_help = "specify output location for generated image ( default: <input folder>.png )"
28
28
  output_style_help = "specify output location for generated stylesheet ( default: <input folder>.<style>)"
29
29
  pngcrush_help = "use pngcrush to optimize generated image"
30
+ padding_help = "add padding to each sprite"
31
+ margin_help = "add margin to each sprite"
30
32
  nocomments_help = "suppress comments in generated stylesheet"
31
33
 
32
34
  op.on("--layout [ORIENTATION]", layout_help) {|value| options[:layout] = value }
@@ -37,6 +39,8 @@ op.on("--cssurl [CSSURL]", cssurl_help) {|value| options[:cssur
37
39
  op.on("--output-image [PATH]", output_image_help) {|value| options[:output_image] = value }
38
40
  op.on("--output-style [PATH]", output_style_help) {|value| options[:output_style] = value }
39
41
  op.on("--pngcrush", pngcrush_help) {|value| options[:pngcrush] = value }
42
+ op.on("--padding [PIXELS]", padding_help) {|value| options[:padding] = value.to_i }
43
+ op.on("--margin [PIXELS]", margin_help) {|value| options[:margin] = value.to_i }
40
44
  op.on("--nocomments", nocomments_help) {|value| options[:nocomments] = true }
41
45
 
42
46
  begin
@@ -2,7 +2,7 @@ module SpriteFactory
2
2
 
3
3
  #----------------------------------------------------------------------------
4
4
 
5
- VERSION = "1.5.3"
5
+ VERSION = "1.6.0"
6
6
  SUMMARY = "Automatic CSS sprite generator"
7
7
  DESCRIPTION = "Combines individual images from a directory into a single sprite image file and creates an appropriate CSS stylesheet"
8
8
  LIB = File.dirname(__FILE__)
@@ -55,8 +55,9 @@ module SpriteFactory
55
55
 
56
56
  module Library # abstract module for using various image libraries
57
57
 
58
- autoload :RMagick, File.join(LIB, 'sprite_factory/library/rmagick') # concrete module for using RMagick (loaded on demand)
59
- autoload :ChunkyPng, File.join(LIB, 'sprite_factory/library/chunky_png') # concrete module for using ChunkyPng (ditto)
58
+ autoload :RMagick, File.join(LIB, 'sprite_factory/library/rmagick') # concrete module for using RMagick (loaded on demand)
59
+ autoload :ChunkyPng, File.join(LIB, 'sprite_factory/library/chunky_png') # concrete module for using ChunkyPng (ditto)
60
+ autoload :ImageMagick, File.join(LIB, 'sprite_factory/library/image_magick') # concrete module for using ImageMagick (ditto)
60
61
 
61
62
  def self.rmagick
62
63
  RMagick
@@ -65,6 +66,10 @@ module SpriteFactory
65
66
  def self.chunkypng
66
67
  ChunkyPng
67
68
  end
69
+
70
+ def self.image_magick
71
+ ImageMagick
72
+ end
68
73
 
69
74
  end
70
75
 
@@ -0,0 +1,74 @@
1
+ module SpriteFactory
2
+ module Library
3
+ module ImageMagick
4
+
5
+ # Represents an error from an underlying ImageMagick call
6
+ class Error < RuntimeError
7
+ attr_reader :command
8
+ attr_reader :args
9
+ attr_reader :output
10
+
11
+ def initialize(msg, command, args, output)
12
+ super(msg)
13
+ @command = command
14
+ @args = args
15
+ @output = output
16
+ end
17
+ end
18
+
19
+ VALID_EXTENSIONS = [:png, :jpg, :jpeg, :gif, :ico]
20
+
21
+ def self.load(files)
22
+ files.map do |filename|
23
+ path = "#{filename}[0]" # layer 0
24
+ output = run("identify", ['-format', '%wx%h', path])
25
+
26
+ width, height = output.chomp.split(/x/).map(&:to_i)
27
+ {
28
+ :filename => filename,
29
+ :path => path,
30
+ :width => width,
31
+ :height => height
32
+ }
33
+ end
34
+ end
35
+
36
+ def self.create(filename, images, width, height)
37
+ # we want to invoke:
38
+ # convert -size #{width}x#{height} xc:none
39
+ # #{input} -geometry +#{x}+#{y} -composite
40
+ # #{output}
41
+
42
+ args = ["-size", "#{width}x#{height}", "xc:none"]
43
+ images.each do |image|
44
+ args += [image[:path], "-geometry", "+#{image[:x]}+#{image[:y]}", "-composite"]
45
+ end
46
+ args << filename
47
+
48
+ run("convert", args)
49
+ true
50
+ end
51
+
52
+ protected
53
+ def self.run(command, args)
54
+ full_command = [command] + args.map(&:to_s)
55
+
56
+ r, w = IO.pipe
57
+ pid = Process.spawn(*full_command, {[:out, :err] => w})
58
+
59
+ w.close
60
+ output = r.read
61
+
62
+ Process.waitpid(pid)
63
+ success = $?.exitstatus == 0 ? true : false
64
+
65
+ if !success
66
+ raise Error.new("error running `#{command}` (check $!.args/$!.output for more information)", command, args, output)
67
+ end
68
+
69
+ output
70
+ end
71
+
72
+ end # module ImageMagick
73
+ end # module Library
74
+ end # module SpriteFactory
@@ -5,8 +5,9 @@ class SpriteFactory::LibraryTest < SpriteFactory::TestCase
5
5
  #--------------------------------------------------------------------------
6
6
 
7
7
  LIBRARIES = {
8
- :rmagick => SpriteFactory::Library::RMagick,
9
- :chunkypng => SpriteFactory::Library::ChunkyPng
8
+ :rmagick => SpriteFactory::Library::RMagick,
9
+ :chunkypng => SpriteFactory::Library::ChunkyPng,
10
+ :image_magick => SpriteFactory::Library::ImageMagick
10
11
  }
11
12
 
12
13
  #--------------------------------------------------------------------------
metadata CHANGED
@@ -1,59 +1,60 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: sprite-factory
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 1
7
- - 5
8
- - 3
9
- version: 1.5.3
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.6.0
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Jake Gordon
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2013-02-21 00:00:00 -08:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2014-03-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: rmagick
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
31
22
  type: :development
32
- version_requirements: *id001
33
- - !ruby/object:Gem::Dependency
34
- name: chunky_png
35
23
  prerelease: false
36
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
37
25
  none: false
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- segments:
42
- - 0
43
- version: "0"
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: chunky_png
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
44
38
  type: :development
45
- version_requirements: *id002
46
- description: Combines individual images from a directory into a single sprite image file and creates an appropriate CSS stylesheet
47
- email:
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: Combines individual images from a directory into a single sprite image
47
+ file and creates an appropriate CSS stylesheet
48
+ email:
48
49
  - jake@codeincomplete.com
49
- executables:
50
+ executables:
50
51
  - sf
51
52
  extensions: []
52
-
53
- extra_rdoc_files:
53
+ extra_rdoc_files:
54
54
  - README.md
55
- files:
55
+ files:
56
56
  - .gitignore
57
+ - Gemfile
57
58
  - LICENSE
58
59
  - README.md
59
60
  - RELEASE_NOTES.md
@@ -64,6 +65,7 @@ files:
64
65
  - lib/sprite_factory/layout/packed.rb
65
66
  - lib/sprite_factory/layout/vertical.rb
66
67
  - lib/sprite_factory/library/chunky_png.rb
68
+ - lib/sprite_factory/library/image_magick.rb
67
69
  - lib/sprite_factory/library/rmagick.rb
68
70
  - lib/sprite_factory/runner.rb
69
71
  - lib/sprite_factory/style.rb
@@ -164,37 +166,29 @@ files:
164
166
  - test/runner_test.rb
165
167
  - test/style_test.rb
166
168
  - test/test_case.rb
167
- has_rdoc: true
168
169
  homepage: https://github.com/jakesgordon/sprite-factory
169
170
  licenses: []
170
-
171
171
  post_install_message:
172
- rdoc_options:
172
+ rdoc_options:
173
173
  - --charset=UTF-8
174
- require_paths:
174
+ require_paths:
175
175
  - lib
176
- required_ruby_version: !ruby/object:Gem::Requirement
176
+ required_ruby_version: !ruby/object:Gem::Requirement
177
177
  none: false
178
- requirements:
179
- - - ">="
180
- - !ruby/object:Gem::Version
181
- segments:
182
- - 0
183
- version: "0"
184
- required_rubygems_version: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ! '>='
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ required_rubygems_version: !ruby/object:Gem::Requirement
185
183
  none: false
186
- requirements:
187
- - - ">="
188
- - !ruby/object:Gem::Version
189
- segments:
190
- - 0
191
- version: "0"
184
+ requirements:
185
+ - - ! '>='
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
192
188
  requirements: []
193
-
194
189
  rubyforge_project:
195
- rubygems_version: 1.3.7
190
+ rubygems_version: 1.8.23
196
191
  signing_key:
197
192
  specification_version: 3
198
193
  summary: Automatic CSS sprite generator
199
194
  test_files: []
200
-