I need to re-size image to constant proportions (f.e. 200x300px), but I need to cut only the bottom of the image, not the top and bottom, like imagecache makes by default. If I add crop action I can change the part of the image which is cropped (if needed). How can I done the same with re-size and crop action?

CommentFileSizeAuthor
#6 aspect_switch-crop_to_top.jpg114.35 KBdman

Comments

fietserwin’s picture

Status: Active » Closed (works as designed)

This is done with effects form Drupal core only: scale to 300 wide, then crop to 200x300 (anchor: center-top). Please file a feature request against Drupal core to add the anchor parameter to "crop and scale" as well (if no issue already exists for this)

If you enable the Image styles admin sub-module you can import the style below:
a:5:{s:4:"isid";s:2:"40";s:4:"name";s:12:"test-1989350";s:6:"module";N;s:7:"storage";i:1;s:7:"effects";a:2:{i:111;a:12:{s:5:"label";s:7:"Schalen";s:4:"help";s:131:"Door te schalen worden de originele verhoudingen behouden. Als één van de dimensies wordt ingevuld zal de andere worden berekend.";s:15:"effect callback";s:18:"image_scale_effect";s:19:"dimensions callback";s:22:"image_scale_dimensions";s:13:"form callback";s:16:"image_scale_form";s:13:"summary theme";s:19:"image_scale_summary";s:6:"module";s:5:"image";s:4:"name";s:11:"image_scale";s:4:"data";a:3:{s:5:"width";s:3:"300";s:6:"height";s:0:"";s:7:"upscale";i:0;}s:4:"ieid";s:3:"111";s:4:"isid";s:2:"40";s:6:"weight";s:3:"-10";}i:110;a:12:{s:5:"label";s:10:"Bijsnijden";s:4:"help";s:105:"Door bij te snijden worden delen van een afbeelding verwijderd zodat deze binnen de opgegeven maten past.";s:15:"effect callback";s:17:"image_crop_effect";s:19:"dimensions callback";s:23:"image_resize_dimensions";s:13:"form callback";s:15:"image_crop_form";s:13:"summary theme";s:18:"image_crop_summary";s:6:"module";s:5:"image";s:4:"name";s:10:"image_crop";s:4:"data";a:3:{s:5:"width";s:3:"300";s:6:"height";s:3:"200";s:6:"anchor";s:10:"center-top";}s:4:"ieid";s:3:"110";s:4:"isid";s:2:"40";s:6:"weight";s:2:"-9";}}}

bigfatguy’s picture

Status: Closed (works as designed) » Active

The problem if I scale and crop separately I'll get black (or white) canvas in background of image, if it has non suitable proportions for such scaling. So I have to make scaling to bigger size f.e. 350x250, than crop to 300x200 with top anchor. But such workaround crops a lot on some images that suites that proportion in favor of those that doesnt.

There is feature request http://drupal.org/node/1252606#comment-5637638 to add anchoring to crop and resize, but it is for D8, as far as I understood.

dman’s picture

I guess you could try the aspect switcher to sort this out for you;

If image proportions are wider than a ratio 2:3, then scale vertically until it's 300 high, then crop the sides to 200 wide
If proportions are squarish or tallish (less than 2:3) then scale to 200 wide, then crop from the top to 300 high

Or something a bit like that

Interestingly, it was a task a bit like this that started the entire imagecache_actions project..

When preparing albums like this one http://thevintageaviator.co.nz/image/tid/94
where a mix of portrait and landscape pics were ALL to be thumbnailed into a landscape preview, 80% of the portraits (which were real head-and-shoulder or full-body 'portraits') looked silly as the default centered crop would cut off everyones face.
So I created the upper 2/3 weighted crop as a custom action. And once I'd solved that I started adding tricky effects everywhere...

fietserwin’s picture

I did some quick calculations with a portrait and landscape size, but extremer ratio's will indeed fail :( dman's solution looks better.

fietserwin’s picture

I did some quick calculations with a portrait and landscape size, but extremer ratio's will indeed fail :( dman's solution looks better.

dman’s picture

StatusFileSize
new114.35 KB

Yeah, that works exactly as planned

200x300_wide

Scale height 300
Crop 200x300

200x300_tall

Scale width 200
Crop 200x300 (top)

200x300_top

Aspect switcher: Portrait size: 200x300_tall. Landscape size: 200x300_wide (switch at 1:1.5)

ezoulou’s picture

Issue summary: View changes

Great! Thanks for taking the time to report.

fietserwin’s picture

Status: Active » Closed (works as designed)

I guess this has been solved by now. Feel free to reopen if not, adding any additional info possible.