[MGNLIMG-212] Don't scale up small images and make it configurable Created: 01/Apr/19  Updated: 29/Aug/22

Status: Open
Project: Imaging
Component/s: None
Affects Version/s: 3.4.2
Fix Version/s: None

Type: Improvement Priority: Neutral
Reporter: Viet Nguyen Assignee: Unassigned
Resolution: Unresolved Votes: 1
Labels: imaging
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Relates
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Release notes required:
Yes
Documentation update required:
Yes
Date of First Response:

 Description   

Follow SUPPORT-9771,

If we upload a small image (as example 80x80) and the content will use an image variation like "large" with a max-width of 1200, the image will be scaled up from 80x80 to 1200x1200. This will destroy the quality of image.

After investigated, I have found that setting 'expand' property to 'false' will not expand your image according to our implementation below:
https://git.magnolia-cms.com/projects/MODULES/repos/imaging/browse/magnolia-imaging/src/main/java/info/magnolia/imaging/operations/cropresize/BoundedResize.java#48

However it is not documented yet. Also if users are using ThemeAwareImageGenerator, this 'expand' property is not configurable from its SimpleResizeVariation.

Expected result:

  • Set info.magnolia.imaging.operations.cropresize.BoundedResize.expand to false by default
  • Document its usage
  • Make it configurable for ThemeAwareImageGenerator somehow


 Comments   
Comment by Jeffrey van der Heide [ 28/Jun/19 ]

@Viet Nguyen: In the mean time we're using our own implementation that extends the default and allows for the expand parameter to be used in the theme e.g.:

class SimpleResizeVariation extends info.magnolia.templating.imaging.variation.SimpleResizeVariation  {

    private boolean expand = true;

    @Inject
    public SimpleResizeVariation(SiteManager siteManager) {
        super(siteManager);
    }

    /**
     * Identical to super class, except for the additional expand parameter.
     */
    @Override
    public void init() {
        if (getImageOperation() == null) {
            final ImageOperationChain<ParameterProvider<Node>> chain = new ImageOperationChain<ParameterProvider<Node>>();
            chain.addOperation(new FromBinaryNode());

            if (super.isCrop()) {
                final AutoCropAndResize resize = new AutoCropAndResize();
                resize.setResizer(new MultiStepResizer());

                if (getWidth() != null) {
                    resize.setTargetWidth(getWidth());
                }
                if (getHeight() != null) {
                    resize.setTargetHeight(getHeight());
                }
                chain.addOperation(resize);
            } else {
                final BoundedResize resize = new BoundedResize();
                resize.setExpand(this.expand);
                resize.setResizer(new MultiStepResizer());

                if (getWidth() != null) {
                    resize.setMaxWidth(getWidth());
                }
                if (getHeight() != null) {
                    resize.setMaxHeight(getHeight());
                }
                chain.addOperation(resize);
            }

            setImageOperation(chain);
        }
    }

    public boolean isExpand() {
        return expand;
    }

    public void setExpand(boolean expand) {
        this.expand = expand;
    }
}

imaging: 
  class: info.magnolia.templating.imaging.VariationAwareImagingSupport 
  variations: 
    logo: 
      class: nl.example.templating.imaging.variation.SimpleResizeVariation 
      width: 256 
      height: 128 
      crop: false 
      expand: false

 

 

Generated at Mon Feb 12 02:13:22 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.