Skip to content

Commit

Permalink
Do not crop picture if crop option is set to false or nil
Browse files Browse the repository at this point in the history
Only if the crop option is set explicitly to true we crop the image, even if `crop_from` or `crop_size` values are given.

This is a change to current behavior where the image was always cropped if `crop_from` or `crop_size` values were given, even if `crop` was set to `false` or left `nil`. This is a very confusing behavior.

Fixes #934
  • Loading branch information
tvdeyen committed Nov 4, 2017
1 parent b99edce commit 0bf8d0a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/models/alchemy/picture/url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def processed_image(image, options = {})

return image unless size.present? && has_convertible_format?

if options[:crop_size].present? && options[:crop_from].present? || options[:crop].present?
if options[:crop]
crop(size, options[:crop_from], options[:crop_size], upsample)
else
resize(size, upsample)
Expand Down
51 changes: 41 additions & 10 deletions spec/models/alchemy/picture_url_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,32 +69,63 @@ def decode_dragon_fly_job(url)
end
end

context "and crop_from and crop_size is passed in" do
context "and crop is set to true" do
let(:options) do
{
crop_size: '123x44',
crop_from: '0x0',
size: '160x120'
size: '160x120',
crop: true
}
end

it "crops and resizes the picture" do
it "crops from center and resizes the picture" do
job = decode_dragon_fly_job(url)
expect(job[1]).to include("-crop 123x44+0+0 -resize 160x120>")
expect(job[1]).to include("160x120#")
end

context "and crop_from and crop_size is passed in" do
let(:options) do
{
crop_size: '123x44',
crop_from: '0x0',
size: '160x120',
crop: true
}
end

it "crops and resizes the picture" do
job = decode_dragon_fly_job(url)
expect(job[1]).to include("-crop 123x44+0+0 -resize 160x120>")
end
end
end

context "and crop is set to true" do
context "and crop is set to false" do
let(:options) do
{
size: '160x120',
crop: true
crop: false
}
end

it "crops from center and resizes the picture" do
it "does not crop the picture" do
job = decode_dragon_fly_job(url)
expect(job[1]).to include("160x120#")
expect(job[1]).to_not include("160x120#")
end

context "and crop_from and crop_size is passed in" do
let(:options) do
{
crop_size: '123x44',
crop_from: '0x0',
size: '160x120',
crop: false
}
end

it "does not crop the picture" do
job = decode_dragon_fly_job(url)
expect(job[1]).to_not include("-crop 123x44+0+0")
end
end
end

Expand Down

0 comments on commit 0bf8d0a

Please sign in to comment.