Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add #width and #height methods to the RMagick processor #1805

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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