The image style "Focal Point Scale and Crop" does not work as expected. No matter where the focal point is (except Y = 0) the crop area stays the same.
My settings for the "Focal Point Scale and Crop" effect: 350px (both width and height).
Test image dimensions: 4912x7360
The main problem lies in the FocalPointEffectBase class:
public function applyEffect(ImageInterface $image) {
// @todo: Get the original image in case there are multiple scale/crop effects?
$this->originalImage = clone $image;
return TRUE;
}
So later in "calculateAnchor" method in lines 235, 238 and 239 there's code, which tries to get the width and height of the original Image. But because we resize the image before cropping, the cloned object is not really the "original" image anymore, cause the properties height and width do get changed "too" (they are just referenced). That leads to unchanged $focal_point variable, because $this->originalImage->getWidth() is actually the same as $image_size['width'], which itself is $image->getWidth().
$focal_point['x'] = (int) round($focal_point['x'] / $this->originalImage->getWidth() * $image_size['width']); // is like (500/1000) * 1000 = 500
$focal_point['y'] = (int) round($focal_point['y'] / $this->originalImage->getHeight() * $image_size['height']);
This error leads to a faulty calculated anchor and thus a faulty crop area.
Comment | File | Size | Author |
---|---|---|---|
#8 | crop_anchor_is_lost-2782073-8.patch | 54.07 KB | bleen |
|
Comments
Comment #2
alex0412 CreditAttribution: alex0412 commentedHere's a basic patch, which saves the width and height of the original image in a new property (because that's all we need for the cropping, not the entire object). I've left the clone there because I'm not sure if it's needed somewhere else. The maintainers sure have a better overview of that ;-)
Comment #3
ahebrank CreditAttribution: ahebrank at NewCity commentedChanging the title to get some attention, since this needs a quick fix. Scale and crop does not work in the current 8.x releases. The patch above works for me.
Comment #4
bleen CreditAttribution: bleen at NBCUniversal commentedUnit tests need to run. They are failing locally ...
Comment #6
bleen CreditAttribution: bleen at NBCUniversal commentedOk ... this is why the unit tests were failing...
What I don't understand now is why the unit tests are passing... If the crops are wrong, then these tests should fail. At minimum, if this patch changes the crops in any way, then these tests should fail.
Comment #7
ahebrank CreditAttribution: ahebrank at NewCity commentedJust taking a quick look at the testing and learning a bit about PHP object copying, I'm speculating that the issue is hidden from testing by how the two images are defined. In testing:
whereas in the plugin proper,
results in what's apparently only a shallow copy of the $image -- meaning that the image dimensions of $originalImage end up changing with each effect applied.
Comment #8
bleen CreditAttribution: bleen at NBCUniversal commentedInteresting ... well, I spent a bunch of time this afternoon completely tearing apart the "calculateAnchor" method and breaking it down into its compnent pieces so I could write much more fine-grained tests.
I think this fortifies things pretty well ...
I'm not bothering with an iterdiff because just about everything changed...
Please test and report back.
Comment #9
hctomThe patch from #8 applies cleanly and solves my problems I had, when my images were autorotated by the image_effects module based in available EXIF data. I don't change the status yet, because I did not check the code so far, but just wanted to report, that it definitely solves the problem.
Comment #11
bleen CreditAttribution: bleen at NBCUniversal commentedI went ahead and committed this