Upload an image in a form programmatically I'm doing a form programmatically. I need to give an option to upload an image and give an option to resize it ( like cropping option ).

I don't know how to do it,  I know that I need to upload the image to a directory and also I suppose that I need to show a relation between the node and the image in the database.

I've created a field called field_img.

So, how can I do it?

This is the form that I've done but I don't know how to give a relation in the database...

form['group_anuncio']['imagen'] = array(
        '#title' =&gt; t('Image'),
        '#type' =&gt; 'managed_file',
        '#upload_validators' =&gt; array('file_validate_extensions' =&gt; array('jpeg jpg png gif')),
        '#upload_location' =&gt; 'public://sites/default/files',
        '#progress_indicator' =&gt; 'throbber',
        '#status' =&gt; FILE_STATUS_PERMANENT,
        '#progress_message' =&gt; 'One moment while we save your file...',
);
I would strongly suggest to use nodes and one of these modules
Comparison of image cropping and resizing modules

If you dont want nodes then you still should be able to use one of crop modules which works with image fields if you use entities, you can use Entity Construction Kit (ECK) module  to create custom entity types