grip 0.5.0 → 0.5.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.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/grip.gemspec +1 -1
  3. data/lib/grip.rb +14 -4
  4. metadata +1 -1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.5.1
data/grip.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{grip}
8
- s.version = "0.5.0"
8
+ s.version = "0.5.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["twoism", "jnunemaker"]
data/lib/grip.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'mongo/gridfs'
2
2
  require 'mime/types'
3
3
  require 'tempfile'
4
- require 'mojo_magick'
4
+ require 'miso'
5
5
 
6
6
  module Grip
7
7
  def self.included(base)
@@ -59,7 +59,7 @@ module Grip
59
59
  end
60
60
 
61
61
  def update_attachment_attributes! name, file, is_version = false
62
- raise Grip::InvalidFileException unless (file.is_a?(File) || file.is_a?(Tempfile))
62
+ raise Grip::InvalidFileException unless (file.is_a?(File) || file.is_a?(Tempfile) || file.is_a?(Miso::Image))
63
63
 
64
64
  self["#{name}_size"] = File.size(file)
65
65
  self["#{name}_name"] = File.basename(file.path)
@@ -86,12 +86,22 @@ module Grip
86
86
 
87
87
  unless opts[:versions].nil?
88
88
  opts[:versions].each do |version,dimensions|
89
- tmp = Tempfile.new("#{attr_name}_#{version}")
90
- MojoMagick::resize(opts[:file].path, tmp.path, dimensions)
89
+
90
+ tmp = Tempfile.new("#{attr_name}_#{version}")
91
+ image = Miso::Image.new(opts[:file].path)
92
+
93
+ image.crop(dimensions[:width], dimensions[:height]) if opts[:crop]
94
+ image.fit(dimensions[:width], dimensions[:height]) unless opts[:crop]
95
+
96
+ image.write(tmp.path)
97
+
98
+ # update <name>_<version> attrs and assign the file
91
99
  send("#{attr_name}_#{version}=", tmp)
100
+
92
101
  GridFS::GridStore.open(self.class.database, self["#{attr_name}_#{version}_path"], 'w', :content_type => self["#{attr_name}_content_type"]) do |f|
93
102
  f.write tmp.read
94
103
  end
104
+
95
105
  end
96
106
  save_to_collection
97
107
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - twoism