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

New: MaxWidth() & MaxHeight() for Image #4211

Closed
jonom opened this issue May 20, 2015 · 6 comments
Closed

New: MaxWidth() & MaxHeight() for Image #4211

jonom opened this issue May 20, 2015 · 6 comments

Comments

@jonom
Copy link
Contributor

jonom commented May 20, 2015

I whipped up a quick extension for a forum post and thought it might be a useful addition to core. Whaddya think? Should I submit a PR?

maxwidthheight

@muskie9
Copy link
Contributor

muskie9 commented May 20, 2015

I like this a lot! +1

@tractorcow
Copy link
Contributor

So Max methods use crop by default? I wonder if that could be made obvious in the method name?

@jonom
Copy link
Contributor Author

jonom commented May 20, 2015

Yeah I was thinking about that too. Maybe should be $CropMaxWidth & $CropMaxHeight?

That could actually allow us to introduce separate functions $MaxWidth and $MaxHeight that act like $SetWidth and $SetHeight with the difference that they don't allow up-sampling.

Related: #4201

@jonom
Copy link
Contributor Author

jonom commented May 24, 2015

Hey @tractorcow what do you think of this outline? Instead of making any changes to existing functions as proposed in #4201, this would only add new functions so would be a safer approach and easier to understand what's going on when you implement them in templates.

I can get a PR together pretty quickly if you think this could make it in to 3.2 :)

New Image functions

In all functions the pixel aspect ratio is preserved (images are not stretched) and it is not possible to up-sample images. The aspect ratio of the image (framing/cropping) may change in the cropping methods.

Method Description Cropping / aspect ratio
ScaleMaxWidth( integer $width ) Proportionally scale down this image if it is wider than the specified width None / Preserved
ScaleMaxHeight( integer $height ) Proportionally scale down this image if it is taller than the specified height None / Preserved
ScaleMax( integer $width, integer $height ) Proportionally scale down this image if it is wider or taller than the specified dimensions None / Preserved
CropMaxWidth( integer $width ) Crop image if it exceeds specified width. Retain height. Crop left and right sides if necessary
CropMaxHeight( integer $height ) Crop image if it exceeds specified height. Retain width. Crop top and bottom if necessary
CropMax( integer $width, integer $height ) Crop this image to the aspect ratio defined by specified width and height. Down-sample to specified dimensions if necessary (don't up-sample). Crop on X or Y axis as necessary

@tractorcow
Copy link
Contributor

Sounds good to me. Make the PR and cc me. :D Please include docs and I'll get it merged into 3.2

jonom added a commit to jonom/silverstripe-framework that referenced this issue May 25, 2015
Added ability to scale and crop images while ensuring upsampling does not occur.
Closes silverstripe#3532, closes silverstripe#4211
jonom added a commit to jonom/silverstripe-framework that referenced this issue May 26, 2015
Added ability to scale and crop images while ensuring upsampling does not occur. Also brought Image docs up to date.
Closes silverstripe#3532, closes silverstripe#4211
jonom added a commit to jonom/silverstripe-framework that referenced this issue May 26, 2015
Added ability to scale and crop images while ensuring upsampling does not occur. Also brought Image docs up to date.
Closes silverstripe#3532, closes silverstripe#4211
jonom added a commit to jonom/silverstripe-framework that referenced this issue May 26, 2015
Added ability to scale and crop images while ensuring upsampling does not occur. Also brought Image docs up to date.
Closes silverstripe#3532, closes silverstripe#4211
jonom added a commit to jonom/silverstripe-framework that referenced this issue May 26, 2015
Added ability to scale and crop images while ensuring upsampling does not occur. Also brought Image docs up to date.
Closes silverstripe#3532, closes silverstripe#4211
jonom added a commit to jonom/silverstripe-framework that referenced this issue May 26, 2015
Added ability to scale and crop images while ensuring upsampling does not occur. Also brought Image docs up to date.
Closes silverstripe#3532, closes silverstripe#4211
jonom added a commit to jonom/silverstripe-framework that referenced this issue May 29, 2015
Added ability to scale and crop images while ensuring upsampling does not occur. Also brought Image docs up to date.
Closes silverstripe#3532, closes silverstripe#4211
jonom added a commit to jonom/silverstripe-framework that referenced this issue Jun 10, 2015
Added ability to scale and crop images while ensuring upsampling does not occur, and brought Image docs up to date.
Closes silverstripe#4211
jonom added a commit to jonom/silverstripe-framework that referenced this issue Jun 10, 2015
Added ability to scale and crop images while ensuring upsampling does not occur, and brought Image docs up to date.
Closes silverstripe#4211
jonom added a commit to jonom/silverstripe-framework that referenced this issue Jun 12, 2015
Renamed image functions with more expressive names. Added CropWidth & CropHeight functions. Added no-upsampling capabilities. Cleaned up Image docs. Closes silverstripe#4211
jonom added a commit to jonom/silverstripe-framework that referenced this issue Jun 13, 2015
Renamed image functions with more expressive names. Added CropWidth & CropHeight functions. Added no-upsampling capabilities. Cleaned up Image docs. Closes silverstripe#4211
@tractorcow
Copy link
Contributor

Merged with #4229

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

No branches or pull requests

3 participants