2

I am having some trouble configuring my image cropping styles. I have an image I want to crop and scale from 600x800 to 140x140, But I only want the cropping to be from the top. At the moment the cropping is equally from the top AND bottom. How can I achieve this, because I can't find any offset setting although Drupal 7 cropping functionality in the API supports it.

Thanks in advance

6

I just tried this on my D7 site I am making and if you go to admin/config/media/image-styles/list you can add a new style. Inside the new style you add an effect to crop and then you can choose the anchor point. The anchor point will allow it to crop from the top instead of equally top and bottom. You can then set your field to display using that style in the display settings or in views or whatever you showing it in.

  • what version are you using ? – Nealv Nov 9 '11 at 22:44
  • 2
    This answer is correct. I think the OP might have the action set to 'Scale and Crop' which does not allow you to set an anchor. Remove that filter and then use crop. (Or maybe scale to a size closer to the final, and then separately crop). – Chance G Nov 10 '11 at 0:43
  • 1
    I'm using the 7.9 version of d7. You should do what Chance said and scale then crop separately that way you can set the anchor. – jdwfly Nov 14 '11 at 21:19
  • Also worth taking a look at this patch - drupal.org/node/1252606#comment-5637638 – Joshua Stewardson Mar 2 '13 at 4:38
2

As said, using the "Scale" and then "Crop" effects separately is the way to go, as "Crop" has an "Anchor" option that allows you to crop from top. (In contrast to the "Scale and Crop" effect you tried.)

However, because you want to scale and crop and not just crop, this technique gets into troubles when source images can be both in portrait and landscape aspect ratio. (Because Drupal lacks a scale effect that scales to cover the target size – it always scales to fit on a canvas defined by your target size.)

Here's a modification that works:

Solution that works for mixed aspect ratio images

  1. Create an image style topcrop_landscape with these effects:

    • "Scale" with "height: 140 px" and "width: " left empty.
    • "Crop" to 140x140 px with "Anchor: center, center".
  2. Create an image style topcrop_portrait with these effects:

    • "Scale" with "width: 140 px" and "height: " left empty.
    • "Crop" to 140x140 px with "Anchor: horizontal center, vertical top".
  3. Create an image style topcrop with these effects:

    • "Aspect Switcher" that selects topcrop_landscape and topcrop_portrait for the landscape and portrait cases, respectively.

Source: inspired by article "Fitting Portrait and Landscape Images to One Size in Drupal"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.