Problem/Motivation

It would be useful if the Scale and Crop image effect had an anchor option, similar to the basic Crop image effect. The anchor type, such as "center-center", is used to set the top left coordinates of the crop area. Currently, Scale and Crop crops only to the center of an image.

Proposed resolution

Have the ScaleAndCropImageEffect descend from CropImageEffect which provides the anchor option, (rather than ScaleImageEffect which it descends from currently) and do the extra math.

Remaining tasks

  1. Write patch with tests
  2. Review
  3. Commit!

User interface changes

The "Scale and crop" image effect now gives the option of choosing an anchor - it works exactly like the "Crop" image effect (which the plugin is descending from).

API changes

This adds a backwards compatible change to the 'scale_and_crop' image toolkit operation: it now can optionally accept 'x' and 'y' arguments to give an offset.

This really only affects people who are implementing image toolkits (like the ImageMagick module), who will need to do something with these arguments if provided.

Data model changes

This adds the "anchor" key to the plugin configuration for this image effect. The default value is "center-center" which matches the old behavior, so if someone imports an images style which with a "Scale and crop" effect that doesn't have the "anchor" key, it'll automatically get set to "center-center".

In short, old configuration will continue to import just fine with no change in behavior.

But tests that look at the configuration will see the new key, and on export the new key will be added. This is the cause of the majority of the test changes, and the changes to the config files in the demo_umami profile.

CommentFileSizeAuthor
#101 1252606-101.patch23.2 KBrlhawk
#97 interdiff.txt918 bytesrlhawk
#97 1252606-97.patch23.27 KBrlhawk
#91 interdiff.txt898 bytesrlhawk
#91 1252606-91.patch22.73 KBrlhawk
#88 interdiff.txt1.51 KBrlhawk
#88 1252606-88.patch22.8 KBrlhawk
#84 interdiff.txt6.21 KBrlhawk
#84 1252606-84.patch22.7 KBrlhawk
#81 interdiff.txt5.75 KBrlhawk
#81 1252606-81.patch23.34 KBrlhawk
#77 drupal-scale-and-crop-anchor-1252606-77.patch11.4 KBsushyl
#76 interdiff.txt2.91 KBdsnopek
#76 drupal-scale-and-crop-anchor-1252606-76.patch16.36 KBdsnopek
#73 interdiff.txt2.54 KBdsnopek
#73 drupal-scale-and-crop-anchor-1252606-73.patch18.2 KBdsnopek
#70 interdiff.txt2.2 KBdsnopek
#70 drupal-scale-and-crop-anchor-1252606-70.patch18.2 KBdsnopek
#67 interdiff.txt2.08 KBdsnopek
#67 drupal-scale-and-crop-anchor-1252606-67.patch17.83 KBdsnopek
#64 interdiff.txt2.22 KBdsnopek
#64 drupal-scale-and-crop-anchor-1252606-64.patch17.05 KBdsnopek
#63 interdiff.txt9.54 KBdsnopek
#63 drupal-scale-and-crop-anchor-1252606-63.patch17.08 KBdsnopek
#61 interdiff.txt506 bytesdsnopek
#61 drupal-scale-and-crop-anchor-1252606-61.patch8.76 KBdsnopek
#58 drupal-scale-and-crop-anchor-1252606-58.patch8.26 KBdsnopek
#51 scale_and_crop_anchor-1252606-51.patch7.61 KBmariiadeny
#46 interdiff.txt854 bytesalansaviolobo
#46 add_crop_anchor_option-1252606-46.patch8.47 KBalansaviolobo
#41 scale_and_crop_anchor-1252606-40.patch8.52 KBrlhawk
#37 D7-scale-and-crop-1252606-37.patch5.04 KBj0rd
#21 scale-and-crop.patch5.08 KBAdysone
#19 scale-and-crop-1252606-19.patch5.59 KBrlhawk
#18 scale-and-crop-1252606-17.patch5.44 KBrlhawk
#14 i1252606_14.patch4.77 KBattiks
#5 i1252606.patch4.52 KBattiks
#3 scale_and_crop-165289-3.patch3.83 KBrlhawk
#1 scale_and_crop-1252606-1.patch3.78 KBrlhawk
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rlhawk’s picture

Here's a patch that implements that feature.

Status: Needs review » Needs work

The last submitted patch, scale_and_crop-1252606-1.patch, failed testing.

rlhawk’s picture

Version: 7.x-dev » 8.x-dev
Status: Needs work » Needs review
FileSize
3.83 KB

Patch recreated for 8.x branch.

Status: Needs review » Needs work

The last submitted patch, scale_and_crop-165289-3.patch, failed testing.

attiks’s picture

FileSize
4.52 KB

Fix for failing test

attiks’s picture

Status: Needs work » Needs review
rlhawk’s picture

Status: Needs review » Needs work

Thanks, attiks!

rlhawk’s picture

Status: Needs work » Needs review
attiks’s picture

Can you mark it as RTBC if it' working for you

rlhawk’s picture

Status: Needs review » Reviewed & tested by the community

I applied the patch and everything works great. Is it unlikely that this would be committed if it were backported to D7?

attiks’s picture

Marking at as such, I assume it isn't a problem, but not my call

webchick’s picture

Issue tags: +Needs backport to D7

Fixing tag.

sun’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/modules/image/image.effects.inc
@@ -158,12 +158,18 @@ function image_crop_effect(&$image, $data) {
- * @return
...
+* @return

Bogus indentation change.

While being there, also add a blank phpDoc line before @return, please.

+++ b/modules/image/image.effects.inc
@@ -158,12 +158,18 @@ function image_crop_effect(&$image, $data) {
+ *   - "anchor": An anchor type, such as "center-center", used to set the top left coordinates of the crop area

Exceeds 80 chars, missing full-stop/period.

20 days to next Drupal core point release.

attiks’s picture

Status: Needs work » Needs review
FileSize
4.77 KB

new patch attached

rlhawk’s picture

Status: Needs review » Reviewed & tested by the community

Tested with no issues.

sun’s picture

Status: Reviewed & tested by the community » Needs review

I'd like someone deeply familiar with the image toolkit API and Image module to RTBC this patch.

andypost’s picture

Status: Needs review » Needs work
+++ b/modules/image/image.effects.incundefined
@@ -158,12 +159,19 @@ function image_crop_effect(&$image, $data) {
+ *   - "anchor": An anchor type, such as "center-center", used to set
+ *               the top left coordinates of the crop area.

Is there explanation about available values? Supose docs should list them

+++ b/includes/image.incundefined
@@ -158,6 +157,8 @@ function image_get_info($filepath, $toolkit = FALSE) {
+ * @param $anchor
+ *   The anchor type to use when cropping.

Same. Could use @see to point to a definition list

14 days to next Drupal core point release.

rlhawk’s picture

Status: Needs work » Needs review
FileSize
5.44 KB

New patch that includes a better description of available values for anchor type. Also added a default value for $anchor in image_scale_and_crop() to avoid breaking any contributed or custom modules that use the function.

rlhawk’s picture

Rerolled patch for new core directory structure.

arbel’s picture

works as is for d7

Adysone’s picture

Version: 8.x-dev » 7.x-dev
FileSize
5.08 KB

Patch for D7, works on 7.12.

jacquesboucar’s picture

the patch is running. i tested in drupal 7.x cloned from github

marcingy’s picture

Version: 7.x-dev » 8.x-dev

Patches need to go into d8 first.

C. Lee’s picture

I'm writing this comment since I'd like to see this patch applied soon. The patch #21 is working fine for me.

attiks’s picture

Issue tags: -Needs backport to D7

#21: scale-and-crop.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +Needs backport to D7

The last submitted patch, scale-and-crop.patch, failed testing.

attiks’s picture

Status: Needs review » Needs work

Patch needs re roll for /core clicked the wrong link before.

attiks’s picture

Status: Needs work » Needs review

#19: scale-and-crop-1252606-19.patch queued for re-testing.

Alan Evans’s picture

There seems to be a problem with editing styles, which I noticed when doing functional testing on this patch. I'm setting this issue back to needs work until i can ascertain whether this issue was introduced by this patch, or if it was also present before patching.

It seems that editing an effect which has a position causes a effect to be added rather than editing the existing. If you save it without changing the position, then it does not create a duplicate effect.

https://skitch.com/e-alanevans/8qeq2/edit-test-post-patch-style-testd85....

Steps to reproduce:

  1. Create a new image style
  2. Add a scale and crop effect to it
  3. Make sure it's saved ...
  4. Edit the effect you just added
  5. Change only the position, and save again
  6. Note the image style now has 2 effects, but only one was intentionally added
Alan Evans’s picture

Status: Needs work » Needs review

OK, I don't think this patch introduced this issue (issue exists also on d8 when not patched), so setting back to needs review and we'll deal with the multiplying image effects elsewhere. The problem is that the effects are referred to by a name derived from their function, so editing an existing effect produces a new unique name, thereby adding it.

Alan Evans’s picture

The multiplying image effects issue does not exist in D7 as effects are referred-to by an int ID, so that's a new issue in D8, but not introduced here. Created #1508872: Image effects duplicate on edit to track this.

I do have to wonder with this patch whether we should maybe display a description of the orientation in the effect summary. For example, here we have no way of knowing which effect has which orientation (well, you could check the url on hover over "edit", but that's not really usable). https://skitch.com/e-alanevans/8qe9k/edit-test-post-patch-style-testd85....

I'll aim to complete testing and review of this, as that's a minor point.

Alan Evans’s picture

So, this works as designed in test:

Code review to follow.

Alan Evans’s picture

I can't really fault this - it's a nice-looking piece of code that does what it sets out to do, so:

+1

Leaving the RTBC for image subsystem maintainers ...

Just a couple of thoughts which might improve it a bit:

  • I'd stand by my previous comment that the Image Effect description should contain the anchor info as well: https://skitch.com/e-alanevans/8qe9k/edit-test-post-patch-style-testd85....
  • is the commentary/messaging/UI generally sufficient? Does everyone understand what "according to anchor" means? I know exactly what you mean because the widget is familiar from using photoshop, but couldn't guarantee that the majority of users would get it. In that sense, the messaging to the end user is more important than the code comments (because you can assume some tech knowledge in people reading code). I'm thinking for the description something along the lines of: "crop the larger dimension, retaining as much image data as possible from the anchored area (the area furthest away from the anchor will be cropped first where needed)". I am sure my text there could be improved-upon though.
  • another option is use photoshop-style visual cues for the widget, but I think that would be adding unnecessary complexity here.
  • the test doesn't really change much - it tests exactly what it tested before, and in fact the default value for anchor on this effect would make this test still appropriate even without the explicit change in code, no? I would recommend testing a variety of anchors and retesting. It only tests the values, not the effect, but that is in keeping with existing tests (the test in this issue does not *need* to improve on the existing test strategy). I think it's borderline whether additional tests are needed on different anchor points in order for this to be RTBC, but I would think it would be preferred.
  • Rambling .... I wonder if we actually can set up a proper automated functional test for images, but that is definitely something for a separate issue: something along the lines of setting up an example image (in a lossless format) in known colors, and after applying various effects, test the colors of particular pixels in the resulting image. I'm not 100% sure whether that's worth doing ... but it would increase our confidence in image effect changes in future though, as it would enable automated testing for those areas
OFF’s picture

How i can do it with d7?

rooby’s picture

@OFF:

I use the patch in comment #21.

j0rd’s picture

I need this patch for D7. Seems to be cropping my images at the bottom, which is not the best place to be cropping.

j0rd’s picture

Version: 8.x-dev » 7.x-dev
Issue summary: View changes
FileSize
5.04 KB

Re-patched D7-dev. Fixed a problem with t() wrappers on the asserts.

fietserwin’s picture

Version: 7.x-dev » 8.x-dev

Please, do not change version because that is what you have or want a patch for. First solve issues in the current development session, then backport it. BTW: As a backport would include UI text changes, I'm afraid this is a no go.

rlhawk’s picture

For anyone who needs this functionality in Drupal 7 and doesn't want to patch core: I've created a sandbox project that adds the anchor feature to the default Scale and Crop image effect.

andypost’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

d8 patch needs re-roll

rlhawk’s picture

Here's a re-roll of the patch for Drupal 8. The tests are almost certainly not correct, but I'm hoping someone else can take a look at them and modify as required.

rlhawk’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 41: scale_and_crop_anchor-1252606-40.patch, failed testing.

alansaviolobo’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 41: scale_and_crop_anchor-1252606-40.patch, failed testing.

alansaviolobo’s picture

Status: Needs work » Needs review
FileSize
8.47 KB
854 bytes

Status: Needs review » Needs work

The last submitted patch, 46: add_crop_anchor_option-1252606-46.patch, failed testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

andypost’s picture

Version: 8.1.x-dev » 8.2.x-dev

Features goes to 8.2

mariiadeny’s picture

Assigned: Unassigned » mariiadeny
mariiadeny’s picture

Assigned: mariiadeny » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs backport to D7, -Needs reroll
FileSize
7.61 KB

Rerolled

andypost’s picture

Issue tags: +Needs backport to D7

This tag probably still makes sense

Status: Needs review » Needs work

The last submitted patch, 51: scale_and_crop_anchor-1252606-51.patch, failed testing.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dsnopek’s picture

Status: Needs work » Needs review
FileSize
8.26 KB

Here's a first (untested) pass at re-rolling this for Drupal 8.6.x. Other than the changes necessary to make it work with a newer Drupal core, this also changes the approach slightly for backwards compatibility: rather than changing the function signature of ImageInterface::scaleAndCrop() it adds a new ImageInterface::scaleAndCropWithAnchor(). This could also be done with a new interface, but since no one will probably ever use ImageInterface without Image, I think this is fine? If this extra work for BC isn't necessary, I'd be happy to switch this back to the old approach.

Anyway, next up is actually testing that it works :-)

dsnopek’s picture

Ha! I just tried that locally and it actually worked. I wasn't expecting that :-)

Status: Needs review » Needs work

The last submitted patch, 58: drupal-scale-and-crop-anchor-1252606-58.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

dsnopek’s picture

Status: Needs work » Needs review
FileSize
8.76 KB
506 bytes

Here's a new patch to try and fix the schema errors.

Status: Needs review » Needs work

The last submitted patch, 61: drupal-scale-and-crop-anchor-1252606-61.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

dsnopek’s picture

Status: Needs work » Needs review
FileSize
17.08 KB
9.54 KB

Here's an attempt to fix the other failures

dsnopek’s picture

Looks like I missed one of the rest tests. Also, this patch adds coding style fixes

The last submitted patch, 63: drupal-scale-and-crop-anchor-1252606-63.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Status: Needs review » Needs work

The last submitted patch, 64: drupal-scale-and-crop-anchor-1252606-64.patch, failed testing. View results

dsnopek’s picture

Status: Needs work » Needs review
FileSize
17.83 KB
2.08 KB

Here's an updated patch which fixes the existing test for scale and crop (basically, the "BC mode"), and also adds a new test to test the new functionality added here. I'm hoping this one will actually pass!

rlhawk’s picture

I tested the functionality and it worked exactly as expected.

dsnopek’s picture

@rlhawk: Thanks for testing!

Reviewing the patch a little myself:

  1. +++ b/core/modules/image/image.module
    @@ -126,6 +126,8 @@ function image_theme() {
    +        'x' => NULL,
    +        'y' => NULL,
    

    This is left over from an earlier version of the patch, but I don't think it's actually necessary. Should be removed.

  2. +++ b/core/tests/Drupal/KernelTests/Core/Theme/StableTemplateOverrideTest.php
    @@ -24,7 +24,8 @@ class StableTemplateOverrideTest extends KernelTestBase {
       protected $templatesToSkip = [
         'views-form-views-form',
    -    'entity-moderation-form'
    +    'entity-moderation-form',
    +    'image-scale-and-crop-summary',
       ];
    

    I'm not sure if this is the right thing to do because I don't know the motivation for this test. Is the idea that Stable makes it's own version of every template in core? If so, we should probably copy the template into Stable.

    The comment on the test is confusing it says "Ensures that Stable overrides all relevant core templates" - what makes a template "relevant"?

    It has copies of all the other image effect summary templates, so I guess we should follow suite...

dsnopek’s picture

Here's a new patch that fixes the things mentioned in #69. I can't think of anything else this patch needs - I think this is ready for wider review!

This issue could probably use an issue summary update, with the usual stuff from the template, but also explaining the backwards compatibility impact of this.

dsnopek’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update

Updated the issue summary based on the template

dsnopek’s picture

Issue summary: View changes

Fix type-o and explain all the seemingly unrelated test changes in the issue summary

dsnopek’s picture

Ah, I did come up with one more thing to change. :-) Thinking about it more, ImageInterface::scaleAndCropWithAnchor() is a bad method name, because we're not passing in the anchor (that's in the image effect plugin), but the offset. So, this patch just renames that to ImageInterface::scaleAndCropWithOffset(). Updating the issue summary too.

mondrake’s picture

Status: Needs review » Needs work

IMHO, we should just avoid to make any change to ImageInterface and Image. Just call $image->apply('scale_and_crop', ['x' => $x, 'y' => $y, 'width' => $width, 'height' => $height]) in the effect and that's all. There was a lot of discussion back in #2073759: Convert toolkit operations to plugins whether to have or not the manipulation methods in the Image class - exactly because the 'apply' method is general whereas hardcoded 'scale', 'crop' etc. methods will have the drawback of leading to BC break if any change needed... and here's the smoking gun in that sense. See the comment #280 there.

See also #872206: Add possibility to not upscale for "Scale and crop" effect comments #152 and #153.

I also think we need an update function in order to update the effect configuration for existing image styles - see the patch in #872206-127: Add possibility to not upscale for "Scale and crop" effect for an example - that did not get in yet but was RTBC'ed at that point by the image system maintainer. NW for that.

dsnopek’s picture

Thanks, @mondrake!

Just call $image->apply('scale_and_crop', ['x' => $x, 'y' => $y, 'width' => $width, 'height' => $height]) in the effect and that's all.

That's a great idea! That avoids the most controversial part of this patch. +1!

I also think we need an update function in order to update the effect configuration for existing image styles

I don't really understand why this is necessary since the default will be used if missing and it'll match existing behavior. But looking at the other issue, it was this comment where an update function was first requested by the image subsystem maintainer:

#872206-105: Add possibility to not upscale for "Scale and crop" effect

So, I guess, if the maintainer wants it, we gotta do it :-)

dsnopek’s picture

Here's a new patch that removes the changes to ImageInterface and Image, because that was the easier change to make. :-) I've updated the issue summary as well. The update hook will come later.

sushyl’s picture

Version: 8.6.x-dev » 8.4.x-dev
FileSize
11.4 KB

Added patch for 8.4.x, noticed and removed some changes related to profile "demo_umami" which does not exist in 8.4.x

mondrake’s picture

Version: 8.4.x-dev » 8.6.x-dev

@sushyl feature requests are always targeted to the current development branch (8.6.x in this case). 8.4.x is unsupported now, so please do not change the version.

sushyl’s picture

My bad!

yogeshmpawar’s picture

Status: Needs work » Needs review

Setting back to "Needs Review" state.

rlhawk’s picture

Here's a new patch that adds a post-update hook, along with a test.

Status: Needs review » Needs work

The last submitted patch, 81: 1252606-81.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

rlhawk’s picture

Ignore that last patch. I will be uploading a new one, along with a a new interdiff.

rlhawk’s picture

Status: Needs work » Needs review
FileSize
22.7 KB
6.21 KB

This patch adds fixes for the failing test and the code standards issue. The interdiff is from drupal-scale-and-crop-anchor-1252606-76.patch in #76.

dsnopek’s picture

Thanks! Those changes look good to me. I'd RTBC, but I think I'm disqualified by working on earlier versions of the patch :-)

andypost’s picture

Status: Needs review » Reviewed & tested by the community

Looks really good to go

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/image/image.post_update.php
    @@ -20,3 +21,26 @@ function image_post_update_image_style_dependencies() {
    +
    +/**
    + * @addtogroup updates-8.6.0
    + * @{
    + */
    ...
    +/**
    + * @} End of "addtogroup updates-8.6.0".
    + */
    

    We no longer to do this.

  2. +++ b/core/modules/image/image.post_update.php
    @@ -20,3 +21,26 @@ function image_post_update_image_style_dependencies() {
    +  foreach (ImageStyle::loadMultiple() as $image_style) {
    +    foreach ($image_style->getEffects() as $effect) {
    +      if ($effect->getPluginId() === 'image_scale_and_crop') {
    +        $image_style->save();
    +        break;
    +      }
    +    }
    

    There's a new scalable way to do this. We should always batch these type of updates as we have no idea how many image styles a site has. See #2949351: Add a helper class to make updating configuration simple

rlhawk’s picture

Status: Needs work » Needs review
FileSize
22.8 KB
1.51 KB

Thanks, @alexpott. That makes sense. Here's a new patch.

tstoeckler’s picture

Status: Needs review » Needs work

Thanks @rlhawk! Some notes on the conversion:

+++ b/core/modules/image/image.post_update.php
@@ -20,3 +21,23 @@ function image_post_update_image_style_dependencies() {
+    $updated = FALSE;
...
+        $image_style->save();
+        $updated = TRUE;
+        break;
...
+    return $updated;
  1. Instead of the $updated variable we can simply return TRUE; inside the if
  2. We should not explicitly save the image style, ConfigEntityUpdater will do that for us.
rlhawk’s picture

Even better. I'll update it.

rlhawk’s picture

Status: Needs work » Needs review
FileSize
22.73 KB
898 bytes

Here's an updated patch.

tstoeckler’s picture

Status: Needs review » Reviewed & tested by the community

Awesome, looks perfect! Back to RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record

Sorry I missed the fact that we should have a change record for this change - since the UI and config are changing.

rlhawk’s picture

Assigned: Unassigned » rlhawk

I'll write the change record.

rlhawk’s picture

Assigned: rlhawk » Unassigned
Status: Needs work » Needs review

The draft change record is here: https://www.drupal.org/node/2972030

mondrake’s picture

Status: Needs review » Needs work
+++ b/core/modules/rest/tests/src/Functional/EntityResource/ImageStyle/ImageStyleResourceTestBase.php
@@ -79,6 +80,7 @@ protected function getExpectedNormalizedEntity() {
diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/ScaleAndCrop.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/ScaleAndCrop.php

diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/ScaleAndCrop.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/ScaleAndCrop.php
index 510020f8d8..2fcda58fad 100644

index 510020f8d8..2fcda58fad 100644
--- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/ScaleAndCrop.php

--- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/ScaleAndCrop.php
+++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/ScaleAndCrop.php

+++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/ScaleAndCrop.php
+++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/ScaleAndCrop.php
@@ -38,8 +38,12 @@ protected function validateArguments(array $arguments) {

@@ -38,8 +38,12 @@ protected function validateArguments(array $arguments) {
 
     $scaleFactor = max($arguments['width'] / $actualWidth, $arguments['height'] / $actualHeight);
 
-    $arguments['x'] = (int) round(($actualWidth * $scaleFactor - $arguments['width']) / 2);
-    $arguments['y'] = (int) round(($actualHeight * $scaleFactor - $arguments['height']) / 2);
+    $arguments['x'] = isset($arguments['x']) ?
+      (int) round($arguments['x']) :
+      (int) round(($actualWidth * $scaleFactor - $arguments['width']) / 2);
+    $arguments['y'] = isset($arguments['y']) ?
+      (int) round($arguments['y']) :
+      (int) round(($actualHeight * $scaleFactor - $arguments['height']) / 2);
     $arguments['resize'] = [
       'width' => (int) round($actualWidth * $scaleFactor),
       'height' => (int) round($actualHeight * $scaleFactor),

Uhmm.. I think we also need to add 'x' and 'y' arguments to the array in the ::arguments() method of the ScaleAndCrop image toolkit operation class. Currently, these are calculated in the ::validateArguments method, but with the change at hand they will be passed in by the image effect plugin.

Contrib toolkits like ImageMagick will have to adjust, also, if they want to support the new arguments.

rlhawk’s picture

Status: Needs work » Needs review
FileSize
23.27 KB
918 bytes

Here's a patch with the 'x' and 'y' arguments added.

mondrake’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs change record

Thanks!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 97: 1252606-97.patch, failed testing. View results

ashutosh.mishra’s picture

the patch is running. i tested in drupal 8.x cloned from github

rlhawk’s picture

Status: Needs work » Needs review
FileSize
23.2 KB

Here's a re-rolled patch.

rlhawk’s picture

mondrake’s picture

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

Adding review credit for patch reviews that affected the patch and explicit testing reviews.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed bf86499 and pushed to 8.6.x. Thanks!

The backport policy now is that a new issue for D7 should be opened - see https://www.drupal.org/core/backport-policy

  • alexpott committed bf86499 on 8.6.x
    Issue #1252606 by rlhawk, dsnopek, attiks, alansaviolobo, MariaDenysyuk...
mondrake’s picture

Status: Fixed » Reviewed & tested by the community

@alexpott I think this chmod went in by mistake

diff --git a/core/scripts/run-tests.sh b/core/scripts/run-tests.sh
index 5dc391e..5dc391e 100644..100755
--- a/core/scripts/run-tests.sh
+++ b/core/scripts/run-tests.sh
mondrake’s picture

Filed #2973804: Add crop anchor option to the Scale and Crop image toolkit operation to enable supporting the same in the ImageMagick module.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 101: 1252606-101.patch, failed testing. View results

mondrake’s picture

Status: Needs work » Fixed

Setting back to Fixed and sent @alexpott a message about #107.

  • alexpott committed 551cb08 on 8.6.x
    Issue #1252606 followup by mondrake: Add crop anchor option to Scale and...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

sushyl’s picture

@alexpott,
Do you think we could cherry pick this for 8.5.x?