image_resizing 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +52 -0
- data/Rakefile +10 -0
- data/image_resizing.gemspec +25 -0
- data/lib/image_resizing.rb +54 -0
- data/lib/image_resizing/version.rb +3 -0
- data/test/1.jpg +0 -0
- data/test/image_resizing_test.rb +44 -0
- data/test/test_helper.rb +3 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 68193fc5819bbca426809b70babdd1aa30952826
|
4
|
+
data.tar.gz: b146b0d9ae9e300d5f501b16e7b5b22be1de14f3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cdc7802050a517c019b90b496a742950334b2007f22533b47c3dc46571ee417c356d07036b688ec005099867b59aa3cc472b5b77fcb690588661ced9e3060e5f
|
7
|
+
data.tar.gz: 7ce34b8ece2f2f032d590f907ec67e570a696d49eae4d66200090f1d8a7cd261ca7e550bf87e3d73395aab01025b65d5520cc00924fb027bb72c59bad51807e3
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Jone Samra
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# ImageResizing
|
2
|
+
|
3
|
+
An easy way to resize images using ImageMagick with Ruby.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
It's based on ImagaMagic & it has to be installed in your OS. What i did to install it on OSX is to type...
|
8
|
+
|
9
|
+
brew install imagemagick
|
10
|
+
|
11
|
+
|
12
|
+
Once the ImagaMagick is installed, install this gem:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'image_resizing'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install image_resizing
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
```uby
|
29
|
+
#Start by requiring...
|
30
|
+
require "image_resizing"
|
31
|
+
|
32
|
+
#Create an instance of the class...
|
33
|
+
ir = ImageResizing::ImageResizer.new
|
34
|
+
|
35
|
+
#Now lets resize an image by setting the width & height of it
|
36
|
+
#The first argument is the new width to set
|
37
|
+
#Second is the height
|
38
|
+
#The third is the path of the image file to resize
|
39
|
+
#And the fourth is The destination path of the newly resized page
|
40
|
+
|
41
|
+
ir.resize_by_width_and_height(100, 70, input.jpg, resized_output.jpg)
|
42
|
+
|
43
|
+
#And lets resize the other image by the ratio in percent
|
44
|
+
#The first argument is the ratio in %.
|
45
|
+
#In the example below, whe chose to minimize the size with 50 % of the original size
|
46
|
+
#The first parameter is the ratio in %
|
47
|
+
#The second is the path of the image file to resize
|
48
|
+
#The third is The destination path of the newly resized page
|
49
|
+
|
50
|
+
ir.resize_by_ratio(50, input2.jpg, resized_output2.jpg)
|
51
|
+
```
|
52
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'image_resizing/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "image_resizing"
|
8
|
+
spec.version = ImageResizing::VERSION
|
9
|
+
spec.authors = ["Jone Samra"]
|
10
|
+
spec.email = ["jonemob@gmail.com"]
|
11
|
+
spec.summary = %q{An easy way to resize images using ImageMagick with Ruby.}
|
12
|
+
spec.description = %q{An easy way to resize images using ImageMagick with Ruby.}
|
13
|
+
spec.homepage = "https://github.com/phenomen2277/image_resizing"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.required_ruby_version = ">= 2.0.0"
|
22
|
+
spec.add_runtime_dependency "rmagick", ">= 2.13.2"
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require "image_resizing/version"
|
2
|
+
require "RMagick"
|
3
|
+
|
4
|
+
module ImageResizing
|
5
|
+
|
6
|
+
class ImageResizer
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
end
|
10
|
+
|
11
|
+
def resize_by_width_and_height(width, height, input_file, output_file)
|
12
|
+
throw_exception_when_input_and_out_files_are_not_given input_file, output_file
|
13
|
+
|
14
|
+
begin
|
15
|
+
image = Magick::Image.read(input_file).first
|
16
|
+
resized_image = image.resize(width, height)
|
17
|
+
resized_image.write(output_file)
|
18
|
+
rescue Exception => e
|
19
|
+
raise RuntimeError, e.message
|
20
|
+
end
|
21
|
+
|
22
|
+
true
|
23
|
+
end
|
24
|
+
|
25
|
+
def resize_by_ratio(ratio_in_percent, input_file, output_file)
|
26
|
+
throw_exception_when_input_and_out_files_are_not_given input_file, output_file
|
27
|
+
|
28
|
+
ratio = ratio_in_percent.to_f / 100.to_f
|
29
|
+
|
30
|
+
begin
|
31
|
+
image = Magick::Image.read(input_file).first
|
32
|
+
resized_image = image.resize(ratio)
|
33
|
+
resized_image.write(output_file)
|
34
|
+
rescue Exception => e
|
35
|
+
raise RuntimeError, e.message
|
36
|
+
end
|
37
|
+
|
38
|
+
true
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
def throw_exception_when_input_and_out_files_are_not_given(input_file, output_file)
|
43
|
+
raise RuntimeError, "Input file does not exist" if input_file.empty? || !file_exists?(input_file)
|
44
|
+
raise RuntimeError, "Output file not given" if output_file.empty?
|
45
|
+
end
|
46
|
+
|
47
|
+
def file_exists?(file)
|
48
|
+
return true if File.file?(file)
|
49
|
+
false
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
data/test/1.jpg
ADDED
Binary file
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class ImageResizingTest < Test::Unit::TestCase
|
4
|
+
def test_successful_resizing_of_image_by_width_and_height
|
5
|
+
ir = create_image_resizer
|
6
|
+
assert ir.resize_by_width_and_height(50, 50, current_dir + "/1.jpg", current_dir + "/resized_by_width_and_height.jpg")
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_successful_resizing_of_image_by_ratio_in_percent
|
10
|
+
ir = create_image_resizer
|
11
|
+
assert ir.resize_by_ratio(50, current_dir + "/1.jpg", current_dir + "/resized_by_ratio.jpg")
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_raising_runtime_error_exception_when_input_file_not_given
|
15
|
+
ir = create_image_resizer
|
16
|
+
assert_raise RuntimeError do
|
17
|
+
ir.resize_by_width_and_height(100, 100, "", current_dir + "/resized_by_ratio.jpg")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_raising_runtime_error_exception_when_output_file_not_given
|
22
|
+
ir = create_image_resizer
|
23
|
+
assert_raise RuntimeError do
|
24
|
+
ir.resize_by_width_and_height(100, 100, current_dir + "/1.jpg", "")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_raising_runtime_error_exception_when_input_file_does_not_exist
|
29
|
+
ir = create_image_resizer
|
30
|
+
assert_raise RuntimeError do
|
31
|
+
ir.resize_by_width_and_height(100, 100, current_dir + "/not_existing_file.jpg", current_dir + "/resized_by_ratio.jpg")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
private
|
37
|
+
def create_image_resizer
|
38
|
+
ImageResizing::ImageResizer.new
|
39
|
+
end
|
40
|
+
|
41
|
+
def current_dir
|
42
|
+
File.expand_path File.dirname(__FILE__)
|
43
|
+
end
|
44
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: image_resizing
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jone Samra
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rmagick
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.13.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.13.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description: An easy way to resize images using ImageMagick with Ruby.
|
56
|
+
email:
|
57
|
+
- jonemob@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- image_resizing.gemspec
|
68
|
+
- lib/image_resizing.rb
|
69
|
+
- lib/image_resizing/version.rb
|
70
|
+
- test/1.jpg
|
71
|
+
- test/image_resizing_test.rb
|
72
|
+
- test/test_helper.rb
|
73
|
+
homepage: https://github.com/phenomen2277/image_resizing
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 2.0.0
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.4.1
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: An easy way to resize images using ImageMagick with Ruby.
|
97
|
+
test_files:
|
98
|
+
- test/1.jpg
|
99
|
+
- test/image_resizing_test.rb
|
100
|
+
- test/test_helper.rb
|