mojo_magick 0.4.4 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +8 -0
- data/init.rb +2 -0
- data/lib/image_magick/fonts.rb +9 -0
- data/lib/image_magick/resource_limits.rb +93 -0
- data/lib/image_resources.rb +0 -125
- data/lib/initializers/hash.rb +8 -0
- data/lib/mojo_magick.rb +13 -2
- data/lib/mojo_magick/font.rb +23 -0
- data/lib/mojo_magick/util/parser.rb +69 -0
- data/lib/mojo_magick/version.rb +1 -1
- data/test/font_test.rb +35 -0
- data/test/fonts_test.rb +12 -0
- data/test/mojo_magick_test.rb +0 -32
- data/test/parser_test.rb +30 -0
- data/test/resource_limits_test.rb +37 -0
- metadata +16 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0cbc5f7e905a8bebd095f21a82f35e689139726e
|
4
|
+
data.tar.gz: 299c155a1930b3fe85fded5371cf8020c9220d31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f882f66230b6266875239d5907a9ce1baa3ba3c7700bbcc92683b152d01bdd1e71667c3d6878fd773667cd8fa827160426c5a657c4a836b9d61578888fbaf1d4
|
7
|
+
data.tar.gz: 49df40b4ef661d3f21750dd76c8f1e21147c3b10699b7ff8ada38d94b5a7f1069cd972e18b63d25d390c49e40a3ed1c60b683c2e9a7170c38fbc1fd435b20d5f
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -122,6 +122,14 @@ complex commands.
|
|
122
122
|
c.file 'output.jpg'
|
123
123
|
end
|
124
124
|
|
125
|
+
### Get a list of available fonts
|
126
|
+
|
127
|
+
fonts = MojoMagick::get_fonts
|
128
|
+
|
129
|
+
fonts.first
|
130
|
+
=> #<MojoMagick::Font:0x000001015a8b90 @name="AvantGarde-Book", @family="AvantGarde", @style="Normal", @stretch="Normal", @weight="400", @glyphs="/usr/local/share/ghostscript/fonts/a010013l.pfb">
|
131
|
+
|
132
|
+
|
125
133
|
### Create a new image with text
|
126
134
|
|
127
135
|
Note: Use with care. If you don't have fonts installed ImageMagick can spin off wildly leaving MojoMagick not knowing what to do. For Unix/MacOSX, you should install freetype and ghostscript.
|
data/init.rb
CHANGED
@@ -0,0 +1,93 @@
|
|
1
|
+
# This module provides some mix-in methods to permit resource limitation commands in MojoMagick
|
2
|
+
module ImageMagick
|
3
|
+
module ResourceLimits
|
4
|
+
@@resource_limits = {}
|
5
|
+
|
6
|
+
# controls limits on memory and other resources for imagemagick.
|
7
|
+
# possible values for type can include:
|
8
|
+
# Area, Disk, File, Map, or Memory
|
9
|
+
# value is byte size for everything but Disk, where it's number of files
|
10
|
+
# type can be string or symbol.
|
11
|
+
# Just limiting Memory will not solve problems with imagemagick going out of
|
12
|
+
# control with resource consumption on certain bad files. You have to set disk,
|
13
|
+
# area and map limits too. Read up on imagemagick website for more.
|
14
|
+
# Different options have different units
|
15
|
+
# DISK: N GB
|
16
|
+
# AREA, MAP, MEMORY: N MB
|
17
|
+
# FILE: N num file handles
|
18
|
+
# Examples:
|
19
|
+
# # set disk to 5 gigabytes limit
|
20
|
+
# MiniMagick::Image::set_limit(:disk => 5)
|
21
|
+
# # set memory to 32mb, map to 64mb and disk to 0
|
22
|
+
# MiniMagick::Image::set_limit(:memory => 32, 'map' => 64, 'disk' => 0)
|
23
|
+
def set_limits(options)
|
24
|
+
mem_fix = 1
|
25
|
+
options.each do |resource, value|
|
26
|
+
@@resource_limits[resource.to_s.downcase.to_sym] = value.to_s
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# remove a limit
|
31
|
+
def remove_limits(*options)
|
32
|
+
mem_fix = 1
|
33
|
+
@@resource_limits.delete_if do |resource, value|
|
34
|
+
resource == options.values_at(options.index(resource))[0].to_s.downcase.to_sym
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# remove limits from resources
|
39
|
+
def unset_limits(options = {})
|
40
|
+
mem_fix = 1
|
41
|
+
@@resource_limits = {}
|
42
|
+
if options[:unset_env]
|
43
|
+
ENV["MAGICK_AREA_LIMIT"]=nil
|
44
|
+
ENV["MAGICK_MAP_LIMIT"]=nil
|
45
|
+
ENV["MAGICK_MEMORY_LIMIT"]=nil
|
46
|
+
ENV["MAGICK_DISK_LIMIT"]=nil
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# returns the default limits that imagemagick is using, when run with no "-limit" parameters
|
51
|
+
# options:
|
52
|
+
# :show_actual_values => true (default false) - will return integers instead of readable values
|
53
|
+
def get_default_limits(options = {})
|
54
|
+
mem_fix = 1
|
55
|
+
parse_limits(options.merge(:get_current_limits => false))
|
56
|
+
end
|
57
|
+
|
58
|
+
# returns the limits that imagemagick is running based on any "set_limits" calls
|
59
|
+
def get_current_limits(options = {})
|
60
|
+
mem_fix = 1
|
61
|
+
parse_limits(options.merge(:get_current_limits => true))
|
62
|
+
end
|
63
|
+
|
64
|
+
alias :get_limits :get_current_limits
|
65
|
+
|
66
|
+
def parse_limits(options)
|
67
|
+
show_actual_values = options[:show_actual_values]
|
68
|
+
if options[:get_current_limits]
|
69
|
+
raw_limits = self.raw_command('identify', '-list resource')
|
70
|
+
else
|
71
|
+
# we run a raw shell command here to obtain limits without applying command line limit params
|
72
|
+
raw_limits = `identify -list resource`
|
73
|
+
end
|
74
|
+
actual_values, readable_values = parser.parse_limits(raw_limits)
|
75
|
+
show_actual_values ? actual_values : readable_values
|
76
|
+
end # parse_limits
|
77
|
+
|
78
|
+
# returns a string suitable for passing as a set of imagemagick params
|
79
|
+
# that contains all the limit constraints
|
80
|
+
def get_limits_as_params
|
81
|
+
retval = ''
|
82
|
+
# we upcase the value here for newer versions of ImageMagick (>=6.8.x)
|
83
|
+
@@resource_limits.each do |type, value|
|
84
|
+
retval += " -limit #{type.to_s} #{value.upcase} "
|
85
|
+
end
|
86
|
+
retval
|
87
|
+
end
|
88
|
+
|
89
|
+
def parser
|
90
|
+
@parser ||= MojoMagick::Util::Parser.new
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
data/lib/image_resources.rb
CHANGED
@@ -1,125 +0,0 @@
|
|
1
|
-
# This module provides some mix-in methods to permit resource limitation commands in MojoMagick
|
2
|
-
# They're stored here simply to make MojoMagick more readable
|
3
|
-
module ImageMagickResources
|
4
|
-
module ResourceLimits
|
5
|
-
@@resource_limits = {}
|
6
|
-
|
7
|
-
# controls limits on memory and other resources for imagemagick.
|
8
|
-
# possible values for type can include:
|
9
|
-
# Area, Disk, File, Map, or Memory
|
10
|
-
# value is byte size for everything but Disk, where it's number of files
|
11
|
-
# type can be string or symbol.
|
12
|
-
# Just limiting Memory will not solve problems with imagemagick going out of
|
13
|
-
# control with resource consumption on certain bad files. You have to set disk,
|
14
|
-
# area and map limits too. Read up on imagemagick website for more.
|
15
|
-
# Different options have different units
|
16
|
-
# DISK: N GB
|
17
|
-
# AREA, MAP, MEMORY: N MB
|
18
|
-
# FILE: N num file handles
|
19
|
-
# Examples:
|
20
|
-
# # set disk to 5 gigabytes limit
|
21
|
-
# MiniMagick::Image::set_limit(:disk => 5)
|
22
|
-
# # set memory to 32mb, map to 64mb and disk to 0
|
23
|
-
# MiniMagick::Image::set_limit(:memory => 32, 'map' => 64, 'disk' => 0)
|
24
|
-
def set_limits(options)
|
25
|
-
mem_fix = 1
|
26
|
-
options.each do |resource, value|
|
27
|
-
@@resource_limits[resource.to_s.downcase.to_sym] = value.to_s
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
# remove a limit
|
32
|
-
def remove_limits(*options)
|
33
|
-
mem_fix = 1
|
34
|
-
@@resource_limits.delete_if do |resource, value|
|
35
|
-
resource == options.values_at(options.index(resource))[0].to_s.downcase.to_sym
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
# remove limits from resources
|
40
|
-
def unset_limits(options = {})
|
41
|
-
mem_fix = 1
|
42
|
-
@@resource_limits = {}
|
43
|
-
if options[:unset_env]
|
44
|
-
ENV["MAGICK_AREA_LIMIT"]=nil
|
45
|
-
ENV["MAGICK_MAP_LIMIT"]=nil
|
46
|
-
ENV["MAGICK_MEMORY_LIMIT"]=nil
|
47
|
-
ENV["MAGICK_DISK_LIMIT"]=nil
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
# returns the default limits that imagemagick is using, when run with no "-limit" parameters
|
52
|
-
# options:
|
53
|
-
# :show_actual_values => true (default false) - will return integers instead of readable values
|
54
|
-
def get_default_limits(options = {})
|
55
|
-
mem_fix = 1
|
56
|
-
parse_limits(options.merge(:get_current_limits => false))
|
57
|
-
end
|
58
|
-
|
59
|
-
# returns the limits that imagemagick is running based on any "set_limits" calls
|
60
|
-
def get_current_limits(options = {})
|
61
|
-
mem_fix = 1
|
62
|
-
parse_limits(options.merge(:get_current_limits => true))
|
63
|
-
end
|
64
|
-
|
65
|
-
alias :get_limits :get_current_limits
|
66
|
-
|
67
|
-
def parse_limits(options)
|
68
|
-
show_actual_values = options[:show_actual_values]
|
69
|
-
if options[:get_current_limits]
|
70
|
-
raw_limits = self.raw_command('identify', '-list resource')
|
71
|
-
else
|
72
|
-
# we run a raw shell command here to obtain limits without applying command line limit params
|
73
|
-
raw_limits = `identify -list resource`
|
74
|
-
end
|
75
|
-
row_limits = raw_limits.split("\n")
|
76
|
-
header = row_limits[0].chomp
|
77
|
-
data = row_limits[2].chomp
|
78
|
-
resources = header.strip.split
|
79
|
-
limits = data.strip.split
|
80
|
-
#resources = header.scan(/^ *([A-Z][a-z]+) +([A-Z][a-z]+) +([A-Z][a-z]+) +([A-Z][a-z]+) +([A-Z][a-z]+)/)[0]
|
81
|
-
#limits = data.scan(/^ *([0-9]+[.0-9a-z]+) +([0-9]+[.0-9a-z]+) +([0-9]+[.0-9a-z]+) +([0-9]+[.0-9a-z]+) +([0-9]+[.0-9a-z]+)/)[0]
|
82
|
-
actual_values = {}
|
83
|
-
readable_values = {}
|
84
|
-
resources.each_index do |i|
|
85
|
-
resource = resources[i].downcase.to_sym
|
86
|
-
scale = limits[i].match(%r{[a-z]+$}) || []
|
87
|
-
value = limits[i].match(%r{^[0-9]+})
|
88
|
-
unscaled_value = value ? value[0].to_i : -1
|
89
|
-
case scale[0]
|
90
|
-
when 'eb'
|
91
|
-
scaled_value = unscaled_value * (2 ** 60)
|
92
|
-
when 'pb'
|
93
|
-
scaled_value = unscaled_value * (2 ** 50)
|
94
|
-
when 'tb'
|
95
|
-
scaled_value = unscaled_value * (2 ** 40)
|
96
|
-
when 'gb'
|
97
|
-
scaled_value = unscaled_value * (2 ** 30)
|
98
|
-
when 'mb'
|
99
|
-
scaled_value = unscaled_value * (2 ** 20)
|
100
|
-
when 'kb'
|
101
|
-
scaled_value = unscaled_value * (2 ** 10)
|
102
|
-
when 'b'
|
103
|
-
scaled_value = unscaled_value
|
104
|
-
else
|
105
|
-
scaled_value = unscaled_value
|
106
|
-
end
|
107
|
-
actual_values[resource] = scaled_value
|
108
|
-
readable_values[resource] = limits[i]
|
109
|
-
end
|
110
|
-
# return actual values if requested in options, otherwise readable values
|
111
|
-
show_actual_values ? actual_values : readable_values
|
112
|
-
end # parse_limits
|
113
|
-
|
114
|
-
# returns a string suitable for passing as a set of imagemagick params
|
115
|
-
# that contains all the limit constraints
|
116
|
-
def get_limits_as_params
|
117
|
-
retval = ''
|
118
|
-
# we upcase the value here for newer versions of ImageMagick (>=6.8.x)
|
119
|
-
@@resource_limits.each do |type, value|
|
120
|
-
retval += " -limit #{type.to_s} #{value.upcase} "
|
121
|
-
end
|
122
|
-
retval
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
data/lib/mojo_magick.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
cwd = File::dirname(__FILE__)
|
2
|
-
|
2
|
+
initializers_dir = File::expand_path(File::join(cwd, 'initializers'))
|
3
|
+
Dir.glob(File::join(initializers_dir, '*.rb')).each { |f| require f }
|
4
|
+
require File::join(cwd, 'mojo_magick/util/parser')
|
5
|
+
require File::join(cwd, 'image_magick/resource_limits')
|
6
|
+
require File::join(cwd, 'image_magick/fonts')
|
3
7
|
require File::join(cwd, 'mojo_magick/opt_builder')
|
8
|
+
require File::join(cwd, 'mojo_magick/font')
|
4
9
|
require 'tempfile'
|
5
10
|
|
6
11
|
|
@@ -60,7 +65,8 @@ module MojoMagick
|
|
60
65
|
class MojoFailed < MojoMagickException; end
|
61
66
|
|
62
67
|
# enable resource limiting functionality
|
63
|
-
extend
|
68
|
+
extend ImageMagick::ResourceLimits
|
69
|
+
extend ImageMagick::Fonts
|
64
70
|
|
65
71
|
def MojoMagick::windows?
|
66
72
|
mem_fix = 1
|
@@ -126,6 +132,11 @@ module MojoMagick
|
|
126
132
|
dest_file
|
127
133
|
end
|
128
134
|
|
135
|
+
def MojoMagick::available_fonts
|
136
|
+
# returns width, height of image if available, nil if not
|
137
|
+
Font.all
|
138
|
+
end
|
139
|
+
|
129
140
|
# returns an empty hash or a hash with :width and :height set (e.g. {:width => INT, :height => INT})
|
130
141
|
# raises MojoFailed when results are indeterminate (width and height could not be determined)
|
131
142
|
def MojoMagick::get_image_size(source_file)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module MojoMagick
|
2
|
+
|
3
|
+
class Font
|
4
|
+
|
5
|
+
attr_accessor :name, :family, :style, :stretch, :weight, :glyphs
|
6
|
+
|
7
|
+
def valid?
|
8
|
+
!(name.nil?)
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(property_hash = {})
|
12
|
+
property_hash.symbolize_keys!
|
13
|
+
[:name, :family, :style, :stretch, :weight, :glyphs].each do |f|
|
14
|
+
setter = "#{f}="
|
15
|
+
self.send(setter, property_hash[f])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.all
|
20
|
+
ImageMagick::Font.all.map{|font_info| Font.new(font_info)}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module MojoMagick
|
2
|
+
module Util
|
3
|
+
class Parser
|
4
|
+
# handle parsing outputs from ImageMagick commands
|
5
|
+
|
6
|
+
def parse_fonts(raw_fonts)
|
7
|
+
font = nil
|
8
|
+
fonts = {}
|
9
|
+
enumerator = raw_fonts.split(/\n/).each
|
10
|
+
name = nil
|
11
|
+
while (begin; line = enumerator.next; rescue StopIteration; line=nil; end) do
|
12
|
+
line.chomp!
|
13
|
+
line = enumerator.next if line.nil? || line.empty? || (/^\s+$/ =~ line)
|
14
|
+
if m = /^\s*Font:\s+(.*)$/.match(line)
|
15
|
+
name = m[1].strip
|
16
|
+
fonts[name] = {:name => name}
|
17
|
+
else
|
18
|
+
key_val = line.split(/:/).map(&:strip)
|
19
|
+
k = key_val[0].downcase.to_sym
|
20
|
+
v = key_val[1]
|
21
|
+
if k && name
|
22
|
+
fonts[name][k] = key_val[1]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
fonts.values.map{|f| MojoMagick::Font.new f}
|
27
|
+
end
|
28
|
+
|
29
|
+
def parse_limits(raw_limits)
|
30
|
+
|
31
|
+
row_limits = raw_limits.split("\n")
|
32
|
+
header = row_limits[0].chomp
|
33
|
+
data = row_limits[2].chomp
|
34
|
+
resources = header.strip.split
|
35
|
+
limits = data.strip.split
|
36
|
+
|
37
|
+
actual_values = {}
|
38
|
+
readable_values = {}
|
39
|
+
resources.each_index do |i|
|
40
|
+
resource = resources[i].downcase.to_sym
|
41
|
+
scale = limits[i].match(%r{[a-z]+$}) || []
|
42
|
+
value = limits[i].match(%r{^[0-9]+})
|
43
|
+
unscaled_value = value ? value[0].to_i : -1
|
44
|
+
case scale[0]
|
45
|
+
when 'eb'
|
46
|
+
scaled_value = unscaled_value * (2 ** 60)
|
47
|
+
when 'pb'
|
48
|
+
scaled_value = unscaled_value * (2 ** 50)
|
49
|
+
when 'tb'
|
50
|
+
scaled_value = unscaled_value * (2 ** 40)
|
51
|
+
when 'gb'
|
52
|
+
scaled_value = unscaled_value * (2 ** 30)
|
53
|
+
when 'mb'
|
54
|
+
scaled_value = unscaled_value * (2 ** 20)
|
55
|
+
when 'kb'
|
56
|
+
scaled_value = unscaled_value * (2 ** 10)
|
57
|
+
when 'b'
|
58
|
+
scaled_value = unscaled_value
|
59
|
+
else
|
60
|
+
scaled_value = unscaled_value
|
61
|
+
end
|
62
|
+
actual_values[resource] = scaled_value
|
63
|
+
readable_values[resource] = limits[i]
|
64
|
+
end
|
65
|
+
[actual_values, readable_values]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/lib/mojo_magick/version.rb
CHANGED
data/test/font_test.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
|
2
|
+
require File::join(File::dirname(__FILE__), 'test_helper')
|
3
|
+
|
4
|
+
IDENTIFY_FONT_RESPONSE =<<EOF
|
5
|
+
Font: Zapf-Dingbats
|
6
|
+
family: Zapf Dingbats
|
7
|
+
style: Normal
|
8
|
+
stretch: Normal
|
9
|
+
weight: 400
|
10
|
+
glyphs: /System/Library/Fonts/ZapfDingbats.ttf
|
11
|
+
Font: Zapfino
|
12
|
+
family: Zapfino
|
13
|
+
style: Italic
|
14
|
+
stretch: Normal
|
15
|
+
weight: 400
|
16
|
+
glyphs: /Library/Fonts/Zapfino.ttf
|
17
|
+
EOF
|
18
|
+
|
19
|
+
class FontTest < Test::Unit::TestCase
|
20
|
+
|
21
|
+
def test_font
|
22
|
+
f = MojoMagick::Font.new
|
23
|
+
assert_equal f.name, nil
|
24
|
+
assert_equal f.valid?, false
|
25
|
+
|
26
|
+
f = MojoMagick::Font.new(:name => "Zapfino", :weight => 400)
|
27
|
+
assert_equal f.name, 'Zapfino'
|
28
|
+
assert_equal f.valid?, true
|
29
|
+
assert_equal f.weight, 400
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
|
data/test/fonts_test.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require File::join(File::dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
class FontsTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_get_fonts
|
6
|
+
fonts = MojoMagick::get_fonts
|
7
|
+
assert fonts.is_a? Array
|
8
|
+
assert fonts.length > 1
|
9
|
+
assert fonts.first.name
|
10
|
+
assert (fonts.first.name.is_a? String)
|
11
|
+
end
|
12
|
+
end
|
data/test/mojo_magick_test.rb
CHANGED
@@ -131,38 +131,6 @@ class MojoMagickTest < Test::Unit::TestCase
|
|
131
131
|
assert_equal 120, dim[:height]
|
132
132
|
end
|
133
133
|
|
134
|
-
def test_resource_limits
|
135
|
-
orig_limits = MojoMagick::get_default_limits
|
136
|
-
assert_equal 7, orig_limits.size
|
137
|
-
orig_limits_test = orig_limits.dup
|
138
|
-
orig_limits_test.delete_if do |resource, value|
|
139
|
-
assert [:area, :map, :disk, :memory, :file, :thread, :time].include?(resource), "Found unexpected resource #{resource}"
|
140
|
-
true
|
141
|
-
end
|
142
|
-
assert_equal 0, orig_limits_test.size
|
143
|
-
|
144
|
-
# set area to 32mb limit
|
145
|
-
MojoMagick::set_limits(:area => '32mb')
|
146
|
-
new_limits = MojoMagick::get_current_limits
|
147
|
-
assert_equal '32mb', new_limits[:area].downcase
|
148
|
-
|
149
|
-
# remove limits on area
|
150
|
-
MojoMagick::remove_limits(:area)
|
151
|
-
new_limits = MojoMagick::get_current_limits
|
152
|
-
assert_equal orig_limits[:area], new_limits[:area]
|
153
|
-
|
154
|
-
# set memory to 64 mb, disk to 0 and
|
155
|
-
MojoMagick::set_limits(:memory => '64mb', :disk => '0b')
|
156
|
-
new_limits = MojoMagick::get_current_limits(:show_actual_values => true)
|
157
|
-
assert_equal 61, new_limits[:memory]
|
158
|
-
assert_equal 0, new_limits[:disk]
|
159
|
-
|
160
|
-
# return to original/default limit values
|
161
|
-
MojoMagick::unset_limits
|
162
|
-
new_limits = MojoMagick::get_current_limits
|
163
|
-
assert_equal orig_limits, new_limits
|
164
|
-
end
|
165
|
-
|
166
134
|
def test_tempfile
|
167
135
|
# Create a tempfile and return the path
|
168
136
|
filename = MojoMagick::tempfile('binary data')
|
data/test/parser_test.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require File::join(File::dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
IDENTIFY_FONT_RESPONSE =<<EOF
|
4
|
+
|
5
|
+
Font: Zapf-Dingbats
|
6
|
+
family: Zapf Dingbats
|
7
|
+
style: Normal
|
8
|
+
stretch: Normal
|
9
|
+
weight: 400
|
10
|
+
glyphs: /System/Library/Fonts/ZapfDingbats.ttf
|
11
|
+
|
12
|
+
Font: Zapfino
|
13
|
+
family: Zapfino
|
14
|
+
style: Italic
|
15
|
+
stretch: Normal
|
16
|
+
weight: 400
|
17
|
+
glyphs: /Library/Fonts/Zapfino.ttf
|
18
|
+
|
19
|
+
|
20
|
+
EOF
|
21
|
+
|
22
|
+
class ParserTest < Test::Unit::TestCase
|
23
|
+
|
24
|
+
def test_parse_fonts
|
25
|
+
parser = MojoMagick::Util::Parser.new
|
26
|
+
parsed_fonts = parser.parse_fonts(IDENTIFY_FONT_RESPONSE)
|
27
|
+
assert_equal parsed_fonts.length, 2
|
28
|
+
assert_equal parsed_fonts[1].style, 'Italic'
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File::join(File::dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
class ResourceLimitsTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_resource_limits
|
6
|
+
orig_limits = MojoMagick::get_default_limits
|
7
|
+
assert_equal 7, orig_limits.size
|
8
|
+
orig_limits_test = orig_limits.dup
|
9
|
+
orig_limits_test.delete_if do |resource, value|
|
10
|
+
assert [:area, :map, :disk, :memory, :file, :thread, :time].include?(resource), "Found unexpected resource #{resource}"
|
11
|
+
true
|
12
|
+
end
|
13
|
+
assert_equal 0, orig_limits_test.size
|
14
|
+
|
15
|
+
# set area to 32mb limit
|
16
|
+
MojoMagick::set_limits(:area => '32mb')
|
17
|
+
new_limits = MojoMagick::get_current_limits
|
18
|
+
assert_equal '32mb', new_limits[:area].downcase
|
19
|
+
|
20
|
+
# remove limits on area
|
21
|
+
MojoMagick::remove_limits(:area)
|
22
|
+
new_limits = MojoMagick::get_current_limits
|
23
|
+
assert_equal orig_limits[:area], new_limits[:area]
|
24
|
+
|
25
|
+
# set memory to 64 mb, disk to 0 and
|
26
|
+
MojoMagick::set_limits(:memory => '64mb', :disk => '0b')
|
27
|
+
new_limits = MojoMagick::get_current_limits(:show_actual_values => true)
|
28
|
+
assert_equal 61, new_limits[:memory]
|
29
|
+
assert_equal 0, new_limits[:disk]
|
30
|
+
|
31
|
+
# return to original/default limit values
|
32
|
+
MojoMagick::unset_limits
|
33
|
+
new_limits = MojoMagick::get_current_limits
|
34
|
+
assert_equal orig_limits, new_limits
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mojo_magick
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Midgley
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-11-
|
13
|
+
date: 2013-11-23 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|
@@ -69,16 +69,25 @@ files:
|
|
69
69
|
- README.md
|
70
70
|
- Rakefile
|
71
71
|
- init.rb
|
72
|
+
- lib/image_magick/fonts.rb
|
73
|
+
- lib/image_magick/resource_limits.rb
|
72
74
|
- lib/image_resources.rb
|
75
|
+
- lib/initializers/hash.rb
|
73
76
|
- lib/mojo_magick.rb
|
77
|
+
- lib/mojo_magick/font.rb
|
74
78
|
- lib/mojo_magick/opt_builder.rb
|
79
|
+
- lib/mojo_magick/util/parser.rb
|
75
80
|
- lib/mojo_magick/version.rb
|
76
81
|
- mojo_magick.gemspec
|
77
82
|
- test/fixtures/5742.jpg
|
78
83
|
- test/fixtures/not_an_image.jpg
|
79
84
|
- test/fixtures/zero_byte_image.jpg
|
85
|
+
- test/font_test.rb
|
86
|
+
- test/fonts_test.rb
|
80
87
|
- test/mojo_magick_test.rb
|
81
88
|
- test/opt_builder_test.rb
|
89
|
+
- test/parser_test.rb
|
90
|
+
- test/resource_limits_test.rb
|
82
91
|
- test/test_helper.rb
|
83
92
|
homepage: http://github.com/bunnymatic/mojo_magick
|
84
93
|
licenses: []
|
@@ -110,11 +119,15 @@ rubyforge_project: mojo_magick
|
|
110
119
|
rubygems_version: 2.0.3
|
111
120
|
signing_key:
|
112
121
|
specification_version: 4
|
113
|
-
summary: mojo_magick-0.4.
|
122
|
+
summary: mojo_magick-0.4.5
|
114
123
|
test_files:
|
115
124
|
- test/fixtures/5742.jpg
|
116
125
|
- test/fixtures/not_an_image.jpg
|
117
126
|
- test/fixtures/zero_byte_image.jpg
|
127
|
+
- test/font_test.rb
|
128
|
+
- test/fonts_test.rb
|
118
129
|
- test/mojo_magick_test.rb
|
119
130
|
- test/opt_builder_test.rb
|
131
|
+
- test/parser_test.rb
|
132
|
+
- test/resource_limits_test.rb
|
120
133
|
- test/test_helper.rb
|