Scaling images on upload I'm using managed_file in a form to uplaod multiple images (D7).

$form['img_upload1'] = array(
'#title' =&gt; t('Image'),
'#type' =&gt; 'managed_file',
'#upload_validators' =&gt; array(
    'file_validate_extensions' =&gt; array('gif png jpg jpeg')),
'#default_value' =&gt; variable_get('img_upload1', ''),
'#upload_location' =&gt; 'public://uploads_users/mydir/'.$userId,
);


Allowed file-extension are checked when the user chooses an image and in the form-validate-function the filesize is checked. The images should have a max hight of 730px or max width of 970px. 

I can find the dimesions of the uploaded picture bud don't know how to resize it. Is there a way to add a scaling-function (an image-style?) to the managed_file-formfield or to the validation-function to resize the image before ore after the upload?

Thanks

UPDATE
Thank you for your hints. The idea behind all was to have the original files available in a defined dimensions for an other purpose. Bud I see the benefits of using the "Drupal-way".
There's no need to scale your images when you upload them, the usual method is to serve a cached version of the scaled image when it's displayed. This is usually accomplished by setting up an image style in the Drupal admin UI that has the effects you need, and then using theme_image_style() to output that image:

$file = file_load($fid);
$options = array(
  'style_name' =&gt; 'image-style-machine-name',
  'alt' =&gt; 'Alternative Text',
  'path' =&gt; $file-&gt;uri
);

$image_output = theme('image_style', $options);


Doing it this way gives the added benefit of your having the original uploaded file available at any time (for example to link through to as a full-sized version of an image, or in a lightbox, etc.)