I vote for a new effect which is as simple as selecting previously applied crop effect, if any.

For example, imagine we have 3 different crop styles which we use for uploaded images, depending on the image composition. Obviously when we print images we want to use applied crop effect but currently it's not possible to know which effect was applied.

I'm preparing a patch with new effect atm.

Comments

OnkelTem’s picture

Status: Active » Needs review
StatusFileSize
new21.71 KB
new4.54 KB

The patch provides new effect called "Select applied Manual Crop selection".

  • It lookups "manualcrop" table for crop effects applied previously and use it for the image.
  • If it finds no selections for the image, it uses "fallback style" for cropping.
  • If there is not "fallback style", it passes the image through untouched.

Configuration form example:
43.png

OnkelTem’s picture

For dimensions transformations to work (i.e. width and height attributes on <img>) see this followup: #1937342: Provide dimensions callback for Select effect

matthijs’s picture

Hi,

Thanks for your patch, but unfortunately I don't fully understand the point of this effect... Could you explain it a bit more?

Matthijs

OnkelTem’s picture

I'll try :)
It is similar to Reuse effect, but differs from it the next things: while with Reuse you specify which crop style to take, this new effect picks a style automatically — it just selects applied style via consulting manualcrop table, and if no crop was applied for the image, it falls back to one specified.

Use case:

Imagine you have vertical and horizontal photos, and you want to crop them appropriately, so you define two styles:

  • crop_200x150 — for horizontal photos
  • crop_100x150 — for vertical photos

and use either of them when uploading photos.

Now you want to list photos in a gallery e.g. with Views but how would you configure image formatter to print a photo using applied crop effect? This effect is the answer. You just create a style using "Select" effect and whenever a photo is requested via it, it will return an image with either 200x150 or 100x150.

Does it make things clearer?

OnkelTem’s picture

StatusFileSize
new4.54 KB

Fixing minor typo + reroll on the lastest "7.x-1.x"

matthijs’s picture

Assigned: Unassigned » matthijs

Allright, I get it now, thanks! I'll review and commit your patch soon.

Thanks again!

Matthijs

OnkelTem’s picture

Ok, good.

There is a place in my patch which I dislike:

+  $form['manualcrop_select_help'] = array(
+    '#type' => 'markup',
+    '#markup' => '<label>' . t('List of available styles') . '</label>' . $a,
+  );

I was not sure what element I can use instead of "markup" to not add "label" manually.

matthijs’s picture

Maybe you can use the form type "item"?

OnkelTem’s picture

StatusFileSize
new6.29 KB

This is updated version of the patch.

  • Effect form code is more clean now.
  • Added manualcrop_select_summary to the theme array to fix lacking summary.
  • Added 'manualcrop_select' effect to the exclude list of _manualcrop_is_own_effect(). Also I took the liberty to refactor this helper function to make it easier to read. It was:
    function _manualcrop_is_own_effect($effect, $crop_effect = NULL) {
      return ($effect['module'] == 'manualcrop' && (is_null($crop_effect) || ($crop_effect ^ ($effect['name'] == 'manualcrop_reuse'))));
    }
    

    and now reads as:

    function _manualcrop_is_own_effect($effect, $crop_effect = NULL) {
      if ($effect['module'] == 'manualcrop') {
        if (is_null($crop_effect)) {
          return TRUE;
        };
        return $crop_effect ^ in_array($effect['name'], array('manualcrop_reuse', 'manualcrop_select'));
      }
      return FALSE;
    }
    
OnkelTem’s picture

I started getting a warning: Notice: Undefined index: reusestyle в функции manualcrop_preprocess_image() (строка 791 в файле /var/www/lib/d7_dev/extensions/modules/manual-crop/manualcrop.module).

Nevermind, I'll fix it. The reason - manualcrop_preprocess_image() expects only 'reusestyle' as style_name.

OnkelTem’s picture

StatusFileSize
new7.82 KB

New version of the select effect patch.

* Now fallback styles option list include only other styles, not manual-crop based
* Added handling of the effect transformations to manualcrop_preprocess_image()

OnkelTem’s picture

StatusFileSize
new7.82 KB

Fixed a whitespace :P

matthijs’s picture

Status: Needs review » Fixed

Patch applied an committed! Thanks!

Status: Fixed » Closed (fixed)

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