4

I want to crop an image that is anchored at the center, but only crop the height. How can this be done in Drupal 7?

EDIT: The process needs to be automated. Basically I desire the functionality of the existing crop process for an image style, but without the requirement for having to enter a value for both width and height.

EDIT #2: The width needs to be variable :)

4
  • I think you can add a scale by width (which doesn't require the height), then crop by the same width and the new height
    – Clive
    Commented May 13, 2013 at 16:45
  • You raised an important point that I missed before :) I've updated my question to be more specific. That's a nifty trick though. Commented May 13, 2013 at 16:50
  • Ah ok :) So you're looking to crop an image vertically to a certain height (center cutout), but for the original image width to stay the same? Won't the results be a wee bit unpredictable?
    – Clive
    Commented May 13, 2013 at 17:01
  • 1
    Unpredictable indeed, but the design I'm working with has a specific height utilized, but the width is variable. I don't account for it if it's not in the spec :) Now if they want to pay me to change the spec, that's another thing... Commented May 13, 2013 at 17:05

3 Answers 3

2

You'll have to use custom GD methods I think.

Have a look at this module : https://drupal.org/project/imagecache_actions

With the embed "Custom Actions" module you'll be able to use any gd method you want.

Add a custom filter to an image filter, and find the gd function to use.

In example, to get a B&W picture, the php code to use is :

return imagefilter($image->resource, IMG_FILTER_GRAYSCALE);
1
  • This looks like it will require some research, but is so far the best possible solution I've seen. Commented May 13, 2013 at 18:39
2

Just came across this, and I had a similar issue: crop an image to a fixed height, but leave the width untouched.

ImageCache Actions has a "Define Canvas" option that can take a percentage for one axis ("100% width") and a pixel measurement ("450px") for the other.

I was all set to dig in and monkey with the "Custom Actions" module when I stumbled across "Define Canvas".

1

I had the same problem today, and luckily found the Image max size crop module.

This module adds an image-style which crops an image when the image dimensions are larger then the given dimensions.

In contrary to the core image style crop only one dimension is required.

In my own tests it does work as advertised. Although more accurate would be:

  • ... adds an "image effect", not an "image-style".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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