I think there are cases where it would be useful to be able to:

  • Specify only a height and allow free selection of width.
  • Specify only a width and allow free selection of height.

An aspect ratio would be calculated from the resulting selection, allowing the undeclared (height / width) variable to be calculated.

Comments

lukus’s picture

I've found that altering function epsacrop_crop_image_form($data) after line 264 seems to do the trick ..

I added ..

  $form['width']['#required']=FALSE;
  $form['height']['#required']=FALSE;

.. after the part that loads the standard crop form data.

Not sure how many unintended consequences this might introduce yet though ..

Luke

lukus’s picture

I've also added some validation:

The code above becomes ..

  // Override default
  $form['width']['#required']=FALSE;
  $form['height']['#required']=FALSE;
  
  // Add validation callbacks to ensure that at least one value has been added
  $form['height']['#element_validate'] = array('_epsacrop_height_validate');
  $form['width']['#element_validate'] = array('_epsacrop_width_validate');
   

And the following functions are added ...

/**
 * Validate width information.
 * 
 * @access private
 * @param array $element
 * @param array &$form_state
 * @return void
 */
function _epsacrop_width_validate($element, &$form_state) {
  $value = $element['#value'];

  if (empty($value)) {
    if(empty($form_state['complete form']['data']['height']['#value'])) {
        form_error($element, t('Width cannot be empty without a height value'));
    }
  }
}


/**
 * Validate height information.
 * 
 * @access private
 * @param array $element
 * @param array &$form_state
 * @return void
 */
function _epsacrop_height_validate($element, &$form_state) {
  $value = $element['#value'];

  if (empty($value)) {
    if(empty($form_state['complete form']['data']['width']['#value'])) {
        form_error($element, t('Height cannot be empty without a width value'));
    }
  }
}
lukus’s picture

Here's a patch .. not certain that I've done this correctly - so any advice appreciated.

yvmarques’s picture

Hi,

Thanks for your contribution, its appreciate a lot.

This works for you ? I mean, even in the end-user (when you've to crop a image) the width or height (depends on the context) are free if you don't set width or height ?

Thanks,

-- Yvan

lukus’s picture

Hi Yvan

Thanks for the module - it's really useful :)

This works for me - but I'm a little bit worried that I might have disregarded something important.

Because only one value has been set - the initial view isn't very pleasing (before the crop has been defined) - but for my purposes it seems okay.

Maybe someone else could test and confirm?

Luke

Levdbas’s picture

following

lukus’s picture

Because there's potentially only one dimension stored for the image crop, when it comes to resizing the cropped image - we'll hit a problem as image_resize() requires two dimensions.

To deal with this eventuality, I'd propose changing image_resize() to image_scale on line 352 of epsacrop.module.

Luke

lukus’s picture

Any update on whether this could be included?

yvmarques’s picture

Hi,

I haven't enough spare time to try it deeper, but if it's working I will include it.

Also, can you create a new patch from the last -dev with the change your proposed in #7 it will help me a lot and I can commit it sooner.

Thanks,

-- Yvan

TelFiRE’s picture

Never happened or what?

cwithout’s picture

Status: Active » Needs review
StatusFileSize
new15.86 KB

Tested out the patch with the suggested change from #7. Worked well.

Here's an updated patch.

garbo’s picture

I just applied the patch from #11 and can confirm that it works.

I just want to mention that if you only use one value (e.g. the width) that you probably should check the checkbox for "Ignore if not manually set". In that case the image is being scaled to the set width without cropping.

It's a very handy addition to the already good EPSA crop! (please see if it can be committed)

yvmarques’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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

lukus’s picture

Issue summary: View changes

Hi - was this ever committed?

yvmarques’s picture

Hi,

Yes it was committed in August 9.

https://drupal.org/commitlog/commit/11912/8adb85fcd7be860fb3485003f834d9...

Regards,

-- Yvan

lukus’s picture

Thanks very much :)