The ImageCache Actions module had a feature which allowed you to scale or resize an image by percentage, whereas the core scale and resize effect only accepts numeric values. It would be nice to see this feature migrated to the Image Effect module.

Comments

droath created an issue. See original summary.

woprrr’s picture

Hi, i am interested by this issue because i have already implemented an similar feature in Automated crop project.

    // The width & height of auto crop area must large than min sizes.
    $this->cropBox['width'] = max($this->cropBox['min_width'], $width * $this->autoCropArea);
    $this->cropBox['height'] = max($this->cropBox['min_height'], $height * $this->autoCropArea);

The autoCropArea parameter are used to "adjust" the final size of cropBox.

IMHO, that can be an simple / powerfull option to add in other Effects in option by example 'Scale & crop' 'Automated Crop' 'Resize'.

sam152’s picture

Status: Active » Needs review
StatusFileSize
new4.72 KB

Needed this, here is the plugin.

sam152’s picture

mondrake’s picture

Status: Needs review » Needs work

Thanks @Sam152

  1. The imagecache_actions version of this effect allows setting height/width percentage separately, whereas this patch is limited at defining a single percentage value for scaling. Do we want a separate effect for the split height/width resize, or shall it be included in the patch here? Opinions welcome.
  2. The effect changes the dimensions of the image. As such, it needs to implement ::trasformDimensions.
  3. ::getSummary (and theme_hook entry + template) is missing from the effect.
  4. Need to add a line describing the effect in README.md
  5. The test should extend from \Drupal\image_effects\Tests\ImageEffectsTestBase, which is a WTB test. All the effects in the module extend from it. This will make it easier to convert all tests together later.

As a reference for entering a new effect in a single commit, see http://cgit.drupalcode.org/image_effects/commit/?id=7e79819

sam152’s picture

At this stage, I don't have capacity to implement the changes requested, given #3 works for my use case.

If anyone would like to push this forward, please feel free to implement changes in #5.

woprrr’s picture

@mondrake, Have you already seen automated_crop ? I think in this module we have an effect similar to what you describe. Eg : possibility to enter height/width and/or percents. If that can be usefull here I can purpose a patch to delete it to automated_crop and based this effects onto image_effect (why not).

mondrake’s picture

@woprrr thanks, I had a quick glance - it looks like the automated_crop effect has a very specific use case and it introduces a specific service to manage the crop. That said, if it can be 'extracted' and be able to work in isolation (i.e. without needing that module as a dependency), and fits in the concept here (i.e. just resizing/scaling the source image to a percentage), then as you say, why not?

If you just consider moving the automated_crop effect to the module here, then fine as well, but that would be a separate issue IMHO.

If you want to take it on, please mind the naming conventions and the testing approach described in #5. It can be a bit painful, but please consider we are trying to establish a common pattern for introducing any new effect to this module.

mondrake’s picture

Assigned: Unassigned » mondrake

Taking it on

mondrake’s picture

Assigned: mondrake » Unassigned
Status: Needs work » Needs review
StatusFileSize
new14.06 KB
new17.98 KB

Here's a new patch, addressing points in #5.

  • mondrake committed 03911d5 on 8.x-1.x
    Issue #2827176 by mondrake, Sam152: Scale or Resize an image by a...
mondrake’s picture

Status: Needs review » Fixed

Committed.

Status: Fixed » Closed (fixed)

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