I'm trying to figure out how to crop an image to a square, that is, if the width is less than height, crop to width = 100%, height = old_width, align left center. And vice versa if the height is less than width; width = old_height.

With the aspect switcher I figure I can reduce this to two cases, but I'm not sure how to cut height to "old width". Any ideas?

Comments

trevorbradley’s picture

Hmm, I wonder if:

Scale down to fixed width (i.e. 100 pixels)
Crop to 100x100, align top-left.

would be the way to go.

trevorbradley’s picture

Status: Active » Closed (works as designed)

Yup! That does the trick just fine. If the final step is "Crop down to 100 pixels" (or whatever width you want to render), prescaling one axis like I've done above works perfectly:

Portrait: Scale width to 212 pixels, Crop to 212x212 top left
Landscape: Scale height to 212 pixels, Crop to 212x212 top left
Aspect Switcher: Point to landscape and portrait.

Works great!

I'm not sure how you would crop to a square while keeping the original scale, but I don't need that...

fietserwin’s picture

In D7 this is the "scale and crop" effect (from Drupal core, not this module).

To do what you originally asked, these effects would need to accept keywords like width and height and (simple) expressions to do some arithmetic with it. The canvas and text effects from this module do accept some keywords like top, bottom, left, right and center together with simple expressions like center - 20%. But that is only for positioning, it does not accept width and height as keywords. could be a nice addition to all the scaling and cropping effects that exists.