I'm using FAPI to build a custom form and I use managed_file to upload a picture and save it.
Is it possible to use imagefield crop with the code of form API ?
I have this simple piece of code for my managed_file:

$form['image'] = array(
      '#type' => 'managed_file',
      '#title' => t('My image'),
  );

Thanks.

Comments

8ballsteve’s picture

Am looking for similar functionality - Would love to know how you resolved this?

citricguy’s picture

Did anyone accomplish this yet?

nikolaosinlight’s picture

Yet another person looking for how to do this - does anyone have a solution - module looks great but simply need form API support!

martinpesout’s picture

Issue summary: View changes

Hi, have you resolved this issue? Is it possible to use crop field widget?

Thanks a lot

dhwani’s picture

Hello,
Does anyone have solution ?
I tried :

$form[ 'experience_image1' ] = array(
'#type' => 'managed_file',
'#upload_validators' => array('file_validate_extensions' => array('jpeg jpg png gif')),
'#upload_location' => 'public://picture',
'#progress_indicator' => 'throbber',
'#status' => 1,
'#title' => '',
'#widget' => array('type' => 'imagefield_crop')
);

But crop is not working.

dhwani’s picture

Priority: Normal » Major
Robytfc’s picture

+1 I am also looking for a way of doing this. I've tried using the imagefield_crop field type from 2.x-dev in my form alter but nothing displays.

  $form['menu_images']['square_image'] = array(
    '#type' => 'imagefield_crop',
    '#title' => t('Square image'),
  );

I've also tested using media from the mediafield module and it works as expected when doing this.

  $form['menu_images']['square_image'] = array(
    '#type' => 'media',
    '#title' => t('Square image'),
  );
gateway69’s picture

Did anyone figure this out?

Robytfc’s picture

@gateway69 I managed to get this working by using this sandbox module. https://www.drupal.org/sandbox/meadhu/1870050

awelch’s picture

@Robytfc - did you manage to get the sandbox module working off the bat? I'm getting some issues using it like it not picking up the crop area in the form fields and saving the cropped image incorrectly.
UPDATE:
I realised it is saving the images cropped properly, but doesn't appear to referencing them properly in the files tab in drupal.