Check out wp_insert_attachment()
, found in wp-includes/post.php (Codex article).
So you create your post first using wp_insert_post()
, then attach the file, somewhat like this (modified the Codex):
<?php
$post_id = wp_insert_post( $my_post_data );
$attach_id = wp_insert_attachment( $attachment, $filename, $post_id );
$attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
wp_update_attachment_metadata( $attach_id, $attach_data );
?>
Regarding image resizing/cropping, if you go to your media settings (yoursite.com/wp-admin/options-media.php), you can define custom sizes for your images. Probably not as robust as you're looking for, but if you integrate the output with something like the TimThumb Script, you may get close to what you're looking for.
To see all the variables that the function has, read the commented info in post.php.