The largest disadvantage to this module as I see it is the following limitation:

There is a major difference between Focus Scale and Crop and the standard Scale And Crop: while the latter always returns an image cropped to the exact width and height defined in the action settings, Focus Scale and Crop may return an image smaller than the asked size. This is by design, as Focus Scale and Crop is made to never cut out the focused area, nor to show the area outside the crop rectangle.

Personally, this has bitten me quite a few times and it's terribly annoying because it will bite me in some instances and won't in others with the same image. When it fails, it fails hard and fails silently, especially in an image-intensive layout/design. That being said, I think this could be fixed fairly easily if you were to allow for upscaling of images. This should allow for the images to gain enough size to work without sacrificing the proper image size. Thoughts?

Comments

bleen’s picture

I agree that this is absolutely needed. I would suggest adding a checkbox to the imagefield_focus settings form that is something like this:

❑ Fixed Ratio
Some of your images may be upscaled.

Or something like that...

anrikun’s picture

I will work on a solution for this when I have some time. Patches are welcome in the meantime.

jstoller’s picture

Title: Allow for Upscaling » Crop to exact size (allow upscaling and focus cropping)

I really wanted to use this module, but unfortunately this issue is a deal breaker. I just have too many cases where I am relying on one, or both dimensions of an image being an exact size, to work with a particular layout. I suggest allowing users to specify both minimum and maximum dimension in the image style configuration. Then when cropping, use the following procedure:

  • If a crop box was drawn, then crop the image as specified.
  • If necessary, upscale the image so the width and height are both at least as big as the specified minimum dimensions.
  • Crop to the focus area, but do not reduce either dimension below the minimum specified size.
  • If the image is still larger than the specified maximum dimensions (due to a large focus area), then crop it to fit. Use Smartcrop, if available.

This means I can get a fixed image size, simply by setting the min and max dimensions to the same values. It also means I can get images that are always, say, 300px wide, but allow their heights to vary. This would be incredibly valuable. I realize this has the possibility of creating pixilated output, due to upscaling. It also means that the focus area will not be completely protected from cropping in all cases. However, sometimes maintaining a fixed image size is more important than either of those issues.

anrikun’s picture

I'm working on this to have it out on July.
@all: consider donating to support this project.

wbobeirne’s picture

I took an initial crack at this, but I'd be surprised if I covered all the cases properly. I just needed something in place for the time being, but any improvements are welcome. Attaching patches for 1.0 and dev.

David_Rothstein’s picture

Version: 7.x-1.0 » 7.x-1.x-dev
StatusFileSize
new2.71 KB

I ran into this as well, but without using any cropping; it's possible to hit this issue when the only thing you've set is a focus rectangle. So the above patch didn't work for me. I think the cropping code should probably be left alone actually (just let it do simple cropping), and the only changes should be in the area of the code that deals with the focus rectangle?

Here's a patch that works for me, although I too am not sure I handled all the edge cases correctly either. Also, as @jstoller pointed out above, there are unusual cases where this feature will necessarily result in part of the focus rectangle being left out (example: original image is 500x500, an image style is configured to crop it to 500x100, but the user has created a 200x200 focus rectangle - in that case, there is no way to get the full height of the focus rectangle included while also respecting the image style dimensions). So I've mentioned that possibility in the help text in the patch, in addition to the possibility of upscaling.

longlivelance’s picture

StatusFileSize
new2.09 KB

Patch on #5 was not checking for large/smaller OR equal and in some cases it was causing crops to come out completely wrong. This patch adds those checks to wbobeirne's patch.

heathdutton’s picture

Thank you, #6 is working for us, exactly as desired!

bleen’s picture

I recently created a new module that take a different approach to the idea of focus, but it does ensure that the image is always the size specified in the crop. See https://drupal.org/project/focal_point

jkingsnorth’s picture

Issue summary: View changes

#6 mentions about leaving out an area of the focus rectangle. I absolutely think that in situations where the full focus rectangle cannot be displayed, it should not be displayed. ie: if I specify a crop of 900x100 and my focus rectangle is 200x200, I would expect the final image to crop off the top and bottom of the focus rectangle, resulting in the final dimension I asked for in the image effect.

I've tested the patch in #6 and it works fine for us; so I'm giving #6 another +1, that's two positive reviews =]

bleen’s picture

Status: Needs review » Reviewed & tested by the community
dalguete’s picture

I rerolled the patch in #6, to match the last module version (not dev).

deanflory’s picture

You re-rolled the patch to the 7.x-1.0 (2011-Nov-06) version instead of the 7.x-1.x-dev (2015-Mar-03)? Um...that one is almost 4 years old and aren't patches supposed to be applied to the latest dev in order to move the project forward?

osopolar’s picture

Patch #6 works for me too, in current dev version (7.x-1.0+5-dev, 2016-01-04).