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

Picture is not cropped even though crop: true is set #1279

Closed
robinboening opened this issue Jul 13, 2017 · 4 comments
Closed

Picture is not cropped even though crop: true is set #1279

robinboening opened this issue Jul 13, 2017 · 4 comments
Milestone

Comments

@robinboening
Copy link
Contributor

robinboening commented Jul 13, 2017

The cropping behaviour is broken. I think its broken in more than just one way, but in this issue I will keep it simple and focus on this one behaviour.

You can reproduce it this way:

  1. Upload a image with a dimension of 800x600. (https://reimann.reisen/wp-content/uploads/2017/02/reimann-reisen-potsdam-image009-800x600.jpg)

  2. Assign the picture in an element with an essence picture.

  3. Render the picture in the view with a certain size and cropping set to true.

<%= el.render :picture, size: "400x400", crop: true %>

I expect the picture to be cropped to exactly 400x400 pixel from the center because I put crop: true in there and no manual cropping happened in the UI.

What I see instead is a picture that is not cropped at all. Its scaled down to 400x300 pixel.

Technical explanation of the issue:

It seems this issue was introduced with this PR #1084 when the way of using the picture rendering was changed.

Since we merged it in September 2016 we use picture.url instead of the url helpers. That is totally fine. Since then the crop_from and crop_size options are always set in the options hash. This is totally fine as well. If no manual cropping happened in the UI the values of these two options should to be nil (as defined as the default values in the crop method here https://github.com/AlchemyCMS/alchemy_cms/blob/master/app/models/alchemy/picture/transformations.rb#L45) - and this is not true. These values are empty strings instead of nil. This leads to the situation that even if we actually have no crop_from nor crop_size it will set the cropping dimensions with 0x0+0+0.

DRAGONFLY: shell command: 'convert' '/var/folders/0w/8wchqjw1017bc709wz420lx00000gp/T/dragonfly20170713-73677-484pe6.jpg' '-crop' '0x0+0+0' '-resize' '400x400>' '/var/folders/0w/8wchqjw1017bc709wz420lx00000gp/T/dragonfly20170713-73677-ys72ib.jpg'

This leads to the fact that this picture won't be cropped at all but scaled down to 400x300 pixel.

I will provide a failing test to demonstrate it and a fix as well.

@robinboening robinboening changed the title Picture is not cropped even though crop: true is provided Picture is not cropped even though crop: true is set Jul 13, 2017
@tvdeyen
Copy link
Member

tvdeyen commented Aug 21, 2017

@robinboening any news on this issue?

Since 4.0.0.rc1 we do not jsonify options params anymore. Could you revisit this issue with latest master? It should probably be fixed now.

@tvdeyen
Copy link
Member

tvdeyen commented Nov 3, 2017

#1320 is maybe related as well. @robinboening could you please check if the issue is still present with latest master and not if it's fixed with PR 1320? Thanks

tvdeyen added a commit to tvdeyen/alchemy_cms that referenced this issue Nov 3, 2017
Having empty strings as EssencePicture crop value (`crop_from` or `crop_size`) causes imagemagick to not crop the image but resize only.

Fixes AlchemyCMS#1279
@tvdeyen
Copy link
Member

tvdeyen commented Nov 3, 2017

Confirmed and fixed by #1321

@tvdeyen tvdeyen added this to the 4.0 milestone Nov 3, 2017
@robinboening
Copy link
Contributor Author

Thanks for working on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants