Skip to content

Commit

Permalink
Merge pull request #1805 from mehlah/rmagick_width_and_height
Browse files Browse the repository at this point in the history
Add `#width` and `#height` methods to the RMagick processor
  • Loading branch information
thomasfedb committed Dec 30, 2015
2 parents 464d276 + 9a73434 commit 4f6b5a8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
2 changes: 0 additions & 2 deletions lib/carrierwave/processing/mini_magick.rb
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,6 @@ def append_combine_options(cmd, combine_options)
end
end

private

def mini_magick_image
if url
::MiniMagick::Image.open(url)
Expand Down
26 changes: 26 additions & 0 deletions lib/carrierwave/processing/rmagick.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,28 @@ def resize_to_geometry_string(geometry_string)
end
end

##
# Returns the width of the image.
#
# === Returns
#
# [Integer] the image's width in pixels
#
def width
rmagick_image.columns
end

##
# Returns the height of the image.
#
# === Returns
#
# [Integer] the image's height in pixels
#
def height
rmagick_image.rows
end

##
# Manipulate the image with RMagick. This method will load up an image
# and then pass each of its frames to the supplied block. It will then
Expand Down Expand Up @@ -351,5 +373,9 @@ def destroy_image(image)
image.destroy! if image.respond_to?(:destroy!)
end

def rmagick_image
::Magick::Image.read(current_path).first
end

end # RMagick
end # CarrierWave
8 changes: 8 additions & 0 deletions spec/processing/rmagick_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@
end
end

describe "#width and #height" do
it "should return the width and height of the image" do
@instance.resize_to_fill(200, 300)
expect(@instance.width).to eq(200)
expect(@instance.height).to eq(300)
end
end

describe "test errors" do
context "invalid image file" do
before do
Expand Down

0 comments on commit 4f6b5a8

Please sign in to comment.