robinboening-fleximage 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +14 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +257 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/autotest.rb +5 -0
- data/fleximage.gemspec +179 -0
- data/init.rb +1 -0
- data/lib/dsl_accessor.rb +52 -0
- data/lib/fleximage.rb +56 -0
- data/lib/fleximage/aviary_controller.rb +75 -0
- data/lib/fleximage/blank.rb +70 -0
- data/lib/fleximage/helper.rb +41 -0
- data/lib/fleximage/image_proxy.rb +69 -0
- data/lib/fleximage/legacy_view.rb +63 -0
- data/lib/fleximage/model.rb +711 -0
- data/lib/fleximage/operator/background.rb +62 -0
- data/lib/fleximage/operator/base.rb +189 -0
- data/lib/fleximage/operator/border.rb +50 -0
- data/lib/fleximage/operator/crop.rb +58 -0
- data/lib/fleximage/operator/image_overlay.rb +85 -0
- data/lib/fleximage/operator/resize.rb +92 -0
- data/lib/fleximage/operator/shadow.rb +87 -0
- data/lib/fleximage/operator/text.rb +104 -0
- data/lib/fleximage/operator/trim.rb +14 -0
- data/lib/fleximage/operator/unsharp_mask.rb +36 -0
- data/lib/fleximage/rmagick_image_patch.rb +5 -0
- data/lib/fleximage/view.rb +57 -0
- data/tasks/fleximage_tasks.rake +154 -0
- data/test/fixtures/100x1.jpg +0 -0
- data/test/fixtures/100x100.jpg +0 -0
- data/test/fixtures/1x1.jpg +0 -0
- data/test/fixtures/1x100.jpg +0 -0
- data/test/fixtures/cmyk.jpg +0 -0
- data/test/fixtures/not_a_photo.xml +1 -0
- data/test/fixtures/photo.jpg +0 -0
- data/test/mock_file.rb +21 -0
- data/test/rails_root/app/controllers/application.rb +10 -0
- data/test/rails_root/app/controllers/avatars_controller.rb +85 -0
- data/test/rails_root/app/controllers/photo_bares_controller.rb +85 -0
- data/test/rails_root/app/controllers/photo_dbs_controller.rb +85 -0
- data/test/rails_root/app/controllers/photo_files_controller.rb +85 -0
- data/test/rails_root/app/helpers/application_helper.rb +3 -0
- data/test/rails_root/app/helpers/avatars_helper.rb +2 -0
- data/test/rails_root/app/helpers/photo_bares_helper.rb +2 -0
- data/test/rails_root/app/helpers/photo_dbs_helper.rb +2 -0
- data/test/rails_root/app/helpers/photo_files_helper.rb +2 -0
- data/test/rails_root/app/locales/de.yml +7 -0
- data/test/rails_root/app/locales/en.yml +8 -0
- data/test/rails_root/app/models/abstract.rb +8 -0
- data/test/rails_root/app/models/avatar.rb +4 -0
- data/test/rails_root/app/models/photo_bare.rb +7 -0
- data/test/rails_root/app/models/photo_custom_error.rb +10 -0
- data/test/rails_root/app/models/photo_db.rb +3 -0
- data/test/rails_root/app/models/photo_file.rb +3 -0
- data/test/rails_root/app/models/photo_s3.rb +5 -0
- data/test/rails_root/app/views/avatars/edit.html.erb +17 -0
- data/test/rails_root/app/views/avatars/index.html.erb +20 -0
- data/test/rails_root/app/views/avatars/new.html.erb +16 -0
- data/test/rails_root/app/views/avatars/show.html.erb +8 -0
- data/test/rails_root/app/views/layouts/avatars.html.erb +17 -0
- data/test/rails_root/app/views/layouts/photo_bares.html.erb +17 -0
- data/test/rails_root/app/views/layouts/photo_dbs.html.erb +17 -0
- data/test/rails_root/app/views/layouts/photo_files.html.erb +17 -0
- data/test/rails_root/app/views/photo_bares/edit.html.erb +12 -0
- data/test/rails_root/app/views/photo_bares/index.html.erb +18 -0
- data/test/rails_root/app/views/photo_bares/new.html.erb +11 -0
- data/test/rails_root/app/views/photo_bares/show.html.erb +3 -0
- data/test/rails_root/app/views/photo_dbs/edit.html.erb +32 -0
- data/test/rails_root/app/views/photo_dbs/index.html.erb +26 -0
- data/test/rails_root/app/views/photo_dbs/new.html.erb +31 -0
- data/test/rails_root/app/views/photo_dbs/show.html.erb +23 -0
- data/test/rails_root/app/views/photo_files/edit.html.erb +27 -0
- data/test/rails_root/app/views/photo_files/index.html.erb +24 -0
- data/test/rails_root/app/views/photo_files/new.html.erb +26 -0
- data/test/rails_root/app/views/photo_files/show.html.erb +18 -0
- data/test/rails_root/config/boot.rb +109 -0
- data/test/rails_root/config/database.yml +7 -0
- data/test/rails_root/config/environment.rb +66 -0
- data/test/rails_root/config/environments/development.rb +18 -0
- data/test/rails_root/config/environments/production.rb +19 -0
- data/test/rails_root/config/environments/sqlite3.rb +0 -0
- data/test/rails_root/config/environments/test.rb +22 -0
- data/test/rails_root/config/initializers/inflections.rb +10 -0
- data/test/rails_root/config/initializers/load_translations.rb +4 -0
- data/test/rails_root/config/initializers/mime_types.rb +5 -0
- data/test/rails_root/config/routes.rb +43 -0
- data/test/rails_root/db/migrate/001_create_photo_files.rb +16 -0
- data/test/rails_root/db/migrate/002_create_photo_dbs.rb +16 -0
- data/test/rails_root/db/migrate/003_create_photo_bares.rb +12 -0
- data/test/rails_root/db/migrate/004_create_avatars.rb +13 -0
- data/test/rails_root/db/migrate/005_create_photo_s3s.rb +12 -0
- data/test/rails_root/public/.htaccess +40 -0
- data/test/rails_root/public/404.html +30 -0
- data/test/rails_root/public/422.html +30 -0
- data/test/rails_root/public/500.html +30 -0
- data/test/rails_root/public/dispatch.cgi +10 -0
- data/test/rails_root/public/dispatch.fcgi +24 -0
- data/test/rails_root/public/dispatch.rb +10 -0
- data/test/rails_root/public/favicon.ico +0 -0
- data/test/rails_root/public/images/rails.png +0 -0
- data/test/rails_root/public/index.html +277 -0
- data/test/rails_root/public/javascripts/application.js +2 -0
- data/test/rails_root/public/javascripts/controls.js +963 -0
- data/test/rails_root/public/javascripts/dragdrop.js +972 -0
- data/test/rails_root/public/javascripts/effects.js +1120 -0
- data/test/rails_root/public/javascripts/prototype.js +4225 -0
- data/test/rails_root/public/robots.txt +5 -0
- data/test/rails_root/public/stylesheets/scaffold.css +74 -0
- data/test/rails_root/vendor/plugins/fleximage/init.rb +2 -0
- data/test/s3_stubs.rb +7 -0
- data/test/test_helper.rb +82 -0
- data/test/unit/abstract_test.rb +20 -0
- data/test/unit/basic_model_test.rb +40 -0
- data/test/unit/blank_test.rb +23 -0
- data/test/unit/default_image_path_option_test.rb +16 -0
- data/test/unit/dsl_accessor_test.rb +120 -0
- data/test/unit/file_upload_from_local_test.rb +31 -0
- data/test/unit/file_upload_from_strings_test.rb +23 -0
- data/test/unit/file_upload_from_url_test.rb +35 -0
- data/test/unit/file_upload_to_db_test.rb +41 -0
- data/test/unit/has_store_test.rb +4 -0
- data/test/unit/i18n_messages_test.rb +49 -0
- data/test/unit/image_directory_option_test.rb +20 -0
- data/test/unit/image_proxy_test.rb +17 -0
- data/test/unit/image_storage_format_option_test.rb +31 -0
- data/test/unit/magic_columns_test.rb +34 -0
- data/test/unit/minimum_image_size_test.rb +56 -0
- data/test/unit/operator_base_test.rb +124 -0
- data/test/unit/operator_resize_test.rb +18 -0
- data/test/unit/preprocess_image_option_test.rb +21 -0
- data/test/unit/require_image_option_test.rb +30 -0
- data/test/unit/temp_image_test.rb +23 -0
- data/test/unit/use_creation_date_based_directories_option_test.rb +16 -0
- metadata +258 -0
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test/test_helper'
|
2
|
+
|
3
|
+
class FleximageFileUploadFromUrlTest < Test::Unit::TestCase
|
4
|
+
def test_should_be_valid_with_image_from_url
|
5
|
+
p = PhotoBare.new(:image_file_url => files(:web_photo))
|
6
|
+
assert p.save, 'Record expected to be valid after upload via URL'
|
7
|
+
rescue SocketError
|
8
|
+
print '!'
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_should_be_invalid_with_nonimage_from_url
|
12
|
+
p = PhotoBare.new(:image_file_url => 'http://www.google.com/')
|
13
|
+
assert !p.save, 'Record expected to be invalid after upload via URL'
|
14
|
+
assert_equal 1, p.errors.size
|
15
|
+
assert_equal 'was not a readable image', p.errors.on(:image_file_url)
|
16
|
+
rescue SocketError
|
17
|
+
print '!'
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_should_be_invalid_with_invalid_url
|
21
|
+
p = PhotoBare.new(:image_file_url => 'foo')
|
22
|
+
assert !p.save, 'Record expected to be invalid after upload via URL'
|
23
|
+
assert_equal 1, p.errors.size
|
24
|
+
assert_equal 'was not a readable image', p.errors.on(:image_file_url)
|
25
|
+
rescue SocketError
|
26
|
+
print '!'
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_should_have_an_original_filename
|
30
|
+
p = PhotoFile.new(:image_file_url => files(:web_photo))
|
31
|
+
assert_equal p.image_filename, files(:web_photo)
|
32
|
+
rescue SocketError
|
33
|
+
print '!'
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test/test_helper'
|
2
|
+
|
3
|
+
class FleximageFileUploadToDbTest < Test::Unit::TestCase
|
4
|
+
def test_should_be_valid_with_image
|
5
|
+
p = PhotoDb.new(:image_file => files(:photo))
|
6
|
+
assert p.save, 'Record expected to be allowed to save'
|
7
|
+
|
8
|
+
p = PhotoDb.find(p.id)
|
9
|
+
assert_kind_of Magick::Image, p.load_image
|
10
|
+
assert p.image_file_data.size > 0
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_should_require_an_image
|
14
|
+
p = PhotoDb.new
|
15
|
+
assert !p.save, 'Record expected to not be allowed to save'
|
16
|
+
assert_equal 1, p.errors.size
|
17
|
+
assert_equal 'is required', p.errors.on(:image_file)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_should_require_an_valid_image
|
21
|
+
p = PhotoDb.new(:image_file => files(:not_a_photo))
|
22
|
+
assert !p.save, 'Record expected to not be allowed to save'
|
23
|
+
assert_equal 1, p.errors.size
|
24
|
+
assert_equal 'was not a readable image', p.errors.on(:image_file)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_should_retrieve_a_stored_image
|
28
|
+
id = PhotoDb.create(:image_file => files(:photo)).id
|
29
|
+
p = PhotoDb.find(id)
|
30
|
+
assert_kind_of Magick::Image, p.load_image
|
31
|
+
assert_equal 768, p.load_image.columns
|
32
|
+
assert_equal 1024, p.load_image.rows
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_should_delete_an_image
|
36
|
+
id = PhotoDb.create(:image_file => files(:photo)).id
|
37
|
+
photo = PhotoDb.find(id)
|
38
|
+
photo.destroy
|
39
|
+
assert_nil PhotoDb.find_by_id(id)
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test/test_helper'
|
2
|
+
|
3
|
+
|
4
|
+
class I18nMessagesTest < Test::Unit::TestCase
|
5
|
+
def test_should_have_default_message
|
6
|
+
p = PhotoBare.new
|
7
|
+
p.save
|
8
|
+
assert_equal "is required", p.errors["image_file"]
|
9
|
+
|
10
|
+
p = PhotoBare.new(:image_file => files(:not_a_photo))
|
11
|
+
p.save
|
12
|
+
assert_equal "was not a readable image", p.errors["image_file"]
|
13
|
+
|
14
|
+
p = PhotoBare.new(:image_file => files(:i1x1))
|
15
|
+
p.save
|
16
|
+
assert_equal "is too small (Minimum: 2x2)", p.errors["image_file"]
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_should_have_german_message
|
20
|
+
I18n.locale = "de"
|
21
|
+
p = PhotoBare.new
|
22
|
+
p.save
|
23
|
+
assert_equal "ist erforderlich", p.errors["image_file"]
|
24
|
+
|
25
|
+
p = PhotoBare.new(:image_file => files(:not_a_photo))
|
26
|
+
p.save
|
27
|
+
assert_equal "war nicht lesbar", p.errors["image_file"]
|
28
|
+
|
29
|
+
p = PhotoBare.new(:image_file => files(:i1x1))
|
30
|
+
p.save
|
31
|
+
assert_equal "ist zu klein (Minimalgröße: 2x2)", p.errors["image_file"]
|
32
|
+
ensure
|
33
|
+
I18n.locale = "en"
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_should_have_model_specific_message
|
37
|
+
p = PhotoCustomError.new
|
38
|
+
assert !p.save
|
39
|
+
assert_equal "needs to be attached", p.errors["image_file"]
|
40
|
+
|
41
|
+
p = PhotoCustomError.new(:image_file => files(:not_a_photo))
|
42
|
+
p.save
|
43
|
+
assert_equal "seems to be broken", p.errors["image_file"]
|
44
|
+
|
45
|
+
p = PhotoCustomError.new(:image_file => files(:i1x1))
|
46
|
+
assert !p.save
|
47
|
+
assert_equal "must be bigger (min. size: 2x2)", p.errors["image_file"]
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test/test_helper'
|
2
|
+
|
3
|
+
class FleximageImageDirectoryOptionTest < Test::Unit::TestCase
|
4
|
+
def test_should_store_in_default_image_directory
|
5
|
+
PhotoBare.use_creation_date_based_directories = true
|
6
|
+
p = PhotoBare.create(:image_file => files(:photo))
|
7
|
+
assert_match %r{public/uploads/\d+/\d+/\d+/\d+}, p.file_path
|
8
|
+
assert File.exists?(p.file_path)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_should_set_image_directory
|
12
|
+
PhotoBare.use_creation_date_based_directories = true
|
13
|
+
PhotoBare.image_directory = 'public/uploads/foo'
|
14
|
+
p = PhotoBare.create(:image_file => files(:photo))
|
15
|
+
assert_match %r{public/uploads/foo/\d+/\d+/\d+/\d+}, p.file_path
|
16
|
+
assert File.exists?(p.file_path)
|
17
|
+
ensure
|
18
|
+
PhotoBare.image_directory = 'public/uploads'
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test/test_helper'
|
2
|
+
|
3
|
+
class FleximageImageProxyTest < Test::Unit::TestCase
|
4
|
+
def test_should_have_a_width
|
5
|
+
p = PhotoBare.create(:image_file => files(:photo))
|
6
|
+
p.operate do |image|
|
7
|
+
assert_equal 768, image.width
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_should_have_a_height
|
12
|
+
p = PhotoBare.create(:image_file => files(:photo))
|
13
|
+
p.operate do |image|
|
14
|
+
assert_equal 1024, image.height
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test/test_helper'
|
2
|
+
|
3
|
+
class FleximageImageStorageOptionTest < Test::Unit::TestCase
|
4
|
+
def test_should_have_default_storage_format_png
|
5
|
+
p = PhotoBare.create(:image_file => files(:photo))
|
6
|
+
assert_match %r{\d+\.png$}, p.file_path
|
7
|
+
assert_equal 'PNG', p.load_image.format
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_should_set_image_storage_format_to_jpg
|
11
|
+
PhotoBare.image_storage_format = :jpg
|
12
|
+
p = PhotoBare.create(:image_file => files(:photo))
|
13
|
+
assert_match %r{\d+\.jpg$}, p.file_path
|
14
|
+
assert_equal 'JPG', p.load_image.format
|
15
|
+
ensure
|
16
|
+
PhotoBare.image_storage_format = :png
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_should_have_default_storage_format_png_in_db
|
20
|
+
p = PhotoDb.create(:image_file => files(:photo))
|
21
|
+
assert_equal 'PNG', p.load_image.format
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_should_set_image_storage_format_to_jpg_in_db
|
25
|
+
PhotoDb.image_storage_format = :jpg
|
26
|
+
p = PhotoDb.create(:image_file => files(:photo))
|
27
|
+
assert_equal 'JPG', p.load_image.format
|
28
|
+
ensure
|
29
|
+
PhotoDb.image_storage_format = :png
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test/test_helper'
|
2
|
+
|
3
|
+
class FleximageMagicColumnsTest < Test::Unit::TestCase
|
4
|
+
def test_should_save_data_in_magic_columns_from_local
|
5
|
+
p = PhotoFile.create(:image_file => files(:photo))
|
6
|
+
assert_equal 'photo.jpg', p.image_filename
|
7
|
+
assert_equal 1024, p.image_height
|
8
|
+
assert_equal 768, p.image_width
|
9
|
+
assert_equal 'JPEG', p.image_format
|
10
|
+
assert_equal 'jpg', p.extension
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_should_save_data_in_magic_columns_from_url
|
14
|
+
p = PhotoFile.create(:image_file_url => files(:web_photo))
|
15
|
+
assert_equal files(:web_photo), p.image_filename
|
16
|
+
assert_equal 110, p.image_height
|
17
|
+
assert_equal 276, p.image_width
|
18
|
+
assert_equal 'GIF', p.image_format
|
19
|
+
assert_equal 'gif', p.extension
|
20
|
+
rescue SocketError
|
21
|
+
print '!'
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_should_delete_magic_columns_when_image_is_deleted
|
25
|
+
p = PhotoFile.new(:image_file => files(:photo))
|
26
|
+
p.save
|
27
|
+
|
28
|
+
p = PhotoFile.find(p.id)
|
29
|
+
p.delete_image_file.save
|
30
|
+
|
31
|
+
assert_nil p.image_width
|
32
|
+
assert_nil p.image_height
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test/test_helper'
|
2
|
+
|
3
|
+
|
4
|
+
class BigPhoto < ActiveRecord::Base
|
5
|
+
set_table_name :photo_dbs
|
6
|
+
acts_as_fleximage do
|
7
|
+
validates_image_size '80x60'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class WidePhoto < ActiveRecord::Base
|
12
|
+
set_table_name :photo_dbs
|
13
|
+
acts_as_fleximage do
|
14
|
+
validates_image_size '80x0'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class HighPhoto < ActiveRecord::Base
|
19
|
+
set_table_name :photo_dbs
|
20
|
+
acts_as_fleximage do
|
21
|
+
validates_image_size '0x60'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class MinimumImageSizeTest < Test::Unit::TestCase
|
26
|
+
def test_should_not_save_small_image
|
27
|
+
p = BigPhoto.new(:image_file => files(:i1x1))
|
28
|
+
assert !p.save
|
29
|
+
assert p.errors["image_file"].match(/is too small/)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_should_save_big_image
|
33
|
+
p = BigPhoto.new(:image_file => files(:i100x100))
|
34
|
+
assert p.save
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_should_only_save_wide
|
38
|
+
p = WidePhoto.new(:image_file => files(:i1x100))
|
39
|
+
assert !p.save
|
40
|
+
p = WidePhoto.new(:image_file => files(:i100x1))
|
41
|
+
assert p.save
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_should_only_save_high
|
45
|
+
p = HighPhoto.new(:image_file => files(:i100x1))
|
46
|
+
assert !p.save
|
47
|
+
p = HighPhoto.new(:image_file => files(:i1x100))
|
48
|
+
assert p.save
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_should_include_minimum_dimensions_in_message
|
52
|
+
p = BigPhoto.new(:image_file => files(:i1x1))
|
53
|
+
p.save
|
54
|
+
assert_equal "is too small (Minimum: 80x60)", p.errors["image_file"]
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test/test_helper'
|
2
|
+
|
3
|
+
class FleximageOperatorBaseTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@photo = PhotoBare.create(:image_file => files(:photo))
|
6
|
+
proxy = Fleximage::ImageProxy.new(@photo.load_image, @photo)
|
7
|
+
@op = Fleximage::Operator::Base.new(proxy, @photo.load_image, @photo)
|
8
|
+
|
9
|
+
@other_img = Magick::Image.read(@photo.file_path).first
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_should_raise_operation_not_implemented_exception
|
13
|
+
assert_raise(Fleximage::Operator::OperationNotImplemented) do
|
14
|
+
@photo.operate { |p| p.base }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
# size_to_xy
|
20
|
+
|
21
|
+
def test_should_parse_size_string_to_x_and_y
|
22
|
+
assert_equal [1,2], @op.size_to_xy('1x2')
|
23
|
+
assert_equal [640,480], @op.size_to_xy('640x480')
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_should_parse_size_array_to_x_and_y
|
27
|
+
assert_equal [1,2], @op.size_to_xy([1,2])
|
28
|
+
assert_equal [640,480], @op.size_to_xy([640,480])
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_should_parse_single_size_array_to_square_x_and_y
|
32
|
+
assert_equal [2,2], @op.size_to_xy(2)
|
33
|
+
assert_equal [2,2], @op.size_to_xy('2')
|
34
|
+
assert_equal [480,480], @op.size_to_xy(480)
|
35
|
+
assert_equal [480,480], @op.size_to_xy('480')
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
# scale
|
40
|
+
|
41
|
+
def test_should_scale_the_main_image_and_keep_its_aspect_ratio
|
42
|
+
img = @op.scale(400)
|
43
|
+
assert_equal 400, img.rows
|
44
|
+
assert_equal 300, img.columns
|
45
|
+
assert_equal 400, @photo.load_image.rows
|
46
|
+
assert_equal 300, @photo.load_image.columns
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_should_scale_a_different_image_and_keep_its_aspect_ratio
|
50
|
+
@op.scale(400, @other_img)
|
51
|
+
assert_equal 400, @other_img.rows
|
52
|
+
assert_equal 300, @other_img.columns
|
53
|
+
assert_equal 1024, @photo.load_image.rows
|
54
|
+
assert_equal 768, @photo.load_image.columns
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
# scale and crop
|
59
|
+
|
60
|
+
def test_should_scale_and_crop_the_main_image
|
61
|
+
img = @op.scale_and_crop(400)
|
62
|
+
assert_equal 400, img.rows
|
63
|
+
assert_equal 400, img.columns
|
64
|
+
assert_equal 400, @photo.load_image.rows
|
65
|
+
assert_equal 400, @photo.load_image.columns
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_should_scale_and_crop_a_different_image
|
69
|
+
@op.scale_and_crop(400, @other_img)
|
70
|
+
assert_equal 400, @other_img.rows
|
71
|
+
assert_equal 400, @other_img.columns
|
72
|
+
assert_equal 1024, @photo.load_image.rows
|
73
|
+
assert_equal 768, @photo.load_image.columns
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
# stretch
|
78
|
+
|
79
|
+
def test_should_stretch_the_main_image
|
80
|
+
img = @op.stretch(400)
|
81
|
+
assert_equal 400, img.rows
|
82
|
+
assert_equal 400, img.columns
|
83
|
+
assert_equal 400, @photo.load_image.rows
|
84
|
+
assert_equal 400, @photo.load_image.columns
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_should_stretch_a_different_image
|
88
|
+
@op.stretch(400, @other_img)
|
89
|
+
assert_equal 400, @other_img.rows
|
90
|
+
assert_equal 400, @other_img.columns
|
91
|
+
assert_equal 1024, @photo.load_image.rows
|
92
|
+
assert_equal 768, @photo.load_image.columns
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
def test_should_convert_symbol_to_rmagick_blending_mode
|
97
|
+
assert_equal Magick::MultiplyCompositeOp, @op.symbol_to_blending_mode(:multiply)
|
98
|
+
assert_equal Magick::OverCompositeOp, @op.symbol_to_blending_mode(:over)
|
99
|
+
assert_equal Magick::ScreenCompositeOp, @op.symbol_to_blending_mode(:screen)
|
100
|
+
assert_equal Magick::CopyBlackCompositeOp, @op.symbol_to_blending_mode(:copy_black)
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_should_raise_argument_error_when_no_blend_mode_found
|
104
|
+
assert_raise(ArgumentError) do
|
105
|
+
@op.symbol_to_blending_mode(:foobar)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
# gravity lookup
|
111
|
+
|
112
|
+
def test_should_lookup_correct_gravity
|
113
|
+
assert_equal Magick::CenterGravity, @op.symbol_to_gravity(:center)
|
114
|
+
assert_equal Magick::NorthGravity, @op.symbol_to_gravity(:top)
|
115
|
+
assert_equal Magick::SouthWestGravity, @op.symbol_to_gravity(:bottom_left)
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_should_raise_error_with_a_bad_gravity
|
119
|
+
assert_raise(ArgumentError) do
|
120
|
+
@op.symbol_to_gravity(:foo)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test/test_helper'
|
2
|
+
|
3
|
+
class FleximageOperatorResizeTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@photo = PhotoBare.create(:image_file => files(:photo))
|
6
|
+
proxy = Fleximage::ImageProxy.new(@photo.load_image, @photo)
|
7
|
+
@op = Fleximage::Operator::Base.new(proxy, @photo.load_image, @photo)
|
8
|
+
|
9
|
+
@other_img = Magick::Image.read(@photo.file_path).first
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_should_resize
|
13
|
+
@photo.operate { |p| p.resize '300x400' }
|
14
|
+
assert_equal 400, @photo.load_image.rows
|
15
|
+
assert_equal 300, @photo.load_image.columns
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|