Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
If a crop is in its default state, without specifying a crop at all or after pressing the reset button, i would expect that the default crop displayed will still be applied.
Instead, no crop is applied at all.
The demo examples then even stretch / distort the original image to make it fit the output aspect ratio.
Proposed resolution
Make sure the default crop is applied without any distortion when there is no custom crop configured.
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#20 | 2658652-20.patch | 908 bytes | sanja_m |
|
Comments
Comment #2
woprrr CreditAttribution: woprrr as a volunteer commentedHello @miro,
I think this is not responsibility of IWC. When the user decides not to apply to particular crop it is his responsibility to provide an effect like "scale" in order not to display a distorted image. In the case of style pictures for "Simple example harrows" we define a size height / fixed width for example, but if we decide not to distort the image so just change the configuration and imageStyle put a scale on the width for example. In this case, if we do not have crop defined then the image will not be distorted.
See examples :
Not define any crop
The image is distorded by scale configuration of ImageStyle
I go change the configuration of ImageStyle to set only width to 320 (homotectic rezise)
My same image is not distorded and any crop is applied
If i decide to set a crop i my image is okay too
Comment #3
sanja_m CreditAttribution: sanja_m at MD Systems GmbH commentedI did some research and found that we can apply default crop in two ways:
1. Just send crop values to hidden inputs and message "Cropping applied” remains because crop is always applied, or
2. Send crop values to hidden inputs and remove “Cropping applied” which complicates code a lot in ImageCropWidget::process() (which is already complicated enough), because that value we use to determine crop in various cases.
But IMO if the crop is reset or didn’t set custom on initializing (and message "Cropping applied" doesn't show) it's logical that any crop shouldn't be applied, and therefore I fully agree with @woprrr and I wouldn’t add default crop applying at all.
Comment #4
sanja_m CreditAttribution: sanja_m at MD Systems GmbH commentedWork in progress.
Comment #5
miro_dietikerThx for your opinions but i disagree with u both. ;-)
The ui makes the user expect a different behavior with the default crop output! (it displays a default crop area although it is not altered by the user!)
I have no problem with the ui. I only have a problem with the processing that does not apply default cropping.
I think best is if we change message "cropping applied" to "custom cropping" and other than that always force apply the ratio based crop with default values.
And in case you still disagree, we might need a setting in the crop step if a default crop should be applied when processing. But IMHO this is not needed.
Comment #6
mansspams CreditAttribution: mansspams at Wunder commentedWorkaround for this is to have manual crop followed by resize and crop in image style.
Comment #7
sanja_m CreditAttribution: sanja_m at MD Systems GmbH commentedStill work in progress.
Comment #8
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commentedYesterday I discussed this with @miro_dietiker. We came to the following conclusion.
There are two viable approaches here:
1. Don't apply crop by default at all. This also means crop box should not be displayed until user has selected something.
2. Treat default crop as normal crop (display crop box, display "Crop applied" in vertical tabs). In this case we have to make sure crop is saved correctly even if user didn't modify it at all.
Both approaches make sense in some cases, which means we need to make this configurable on the widget level. It needs to be configurable on a crop type basis as one might want to use one approach for one and other approach for the other. Example: option 1 being used on crop types that don't specify aspect ratio limits and option 2 on the ones that do.
Comment #9
miro_dietikerAgree about configurability of both.
My mindset is 2) and i want to see default values to make the user aware of the default results. Still i'm not sure we need to save the default values. In this case i expect the image style to always apply the default cropping even if there was no cropping stored at all (such as just having the effect configured in an image style without resaving any entity). And thus i also think we would create large garbage records if we always store default crop coordinates.
Comment #10
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commentedI think we should save crop anyway. From image effect's standpoint it is the crop entity which stores all information needed to create an image derivative. If we end up not saving default crop that isn't true any more. It will most likely need to load crop type and field configurations as well. This causes tight coupling of crop UI (IWC in this case) and image effects. It also makes it much harder to replace UI component. Without that we steer away from the idea of the architecture of independent components.
Assuming UI component simply displays how default crop looks is also strange in my opinion. That basically means that field widget knows how image style configuration looks like. In general this isn't an assumption we can make. What happens when/if image style configuration changes? What do we display if more then one image style use the same crop type?
Selected crop area vs. actual image style image are not related 1 to 1. Crop just provides some information for image effect. It is up to image effect to decide how to use that information. I've seen cases in the past where we had two image styles with different aspect rations using same crop type. Crop type was 4:3 and the two styles were 4:3 and 16:9. First style actually ended up looking pretty much the same as crop itself. The other style didn't, but the crop still provided enough information for style to create an image that made sense.
Comment #11
MarinkoIg CreditAttribution: MarinkoIg at MD Systems GmbH commentedHere is the patch, from @sanja_m and me, based on the idea from #8 but for field config, not on a crop type basis.
Comment #13
sanja_m CreditAttribution: sanja_m at MD Systems GmbH commentedFixing failing test.
Comment #14
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commentedLooks very good. We still need to decide on #8, but here are my comment about current patch.
I'd rather pass this configuration via drupalSettings.
If we do ^ we won't need this code any more.
Can we move this hunk inside if?
This code look very similar to the one in Drupal.imageWidgetCrop.reset(). Can we use helper function and get rid of redundant code?
Let's use same label as in the form itself. Consistency FTW.
Same as above.
Comment #15
sanja_m CreditAttribution: sanja_m at MD Systems GmbH commentedFixed all bugs from #14.
Comment #16
CTaPByK CreditAttribution: CTaPByK at MD Systems GmbH commentedLooks very good @sanja_m, i see you fixed all tasks from latest review, also i tested a little and it's works as expected.
Comment #17
woprrr CreditAttribution: woprrr as a volunteer commentedGreat job all ! Thanks @sanja_m works well ! This default comportement is verry better with that patch :).
Comment #19
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commentedNot so fast....
I mentioned in #8 that we should support configuring this on a per crop type basis.
Boolean constants should be uppercase by Drupal coding standards.
Is this hunk still relevant after we started using drupalSettings? I don't think so.
Comment #20
sanja_m CreditAttribution: sanja_m at MD Systems GmbH commentedFixed 2. and 3. from #19, and for point 1. created follow up issue: https://www.drupal.org/node/2662438 as @slashrsm suggested.
Comment #21
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commentedLooks OK. Thanks!
Comment #22
woprrr CreditAttribution: woprrr as a volunteer commentedJust one return about this we need to increment the version of librarie
If w not add this the js of existant instance are not updated.
Comment #24
woprrr CreditAttribution: woprrr as a volunteer commentedSorry to fast previous commit :s ! Now is perfect i ve increment the libraries version. Thanks for this awesome job!!!!