A while back I was asking about how to easily incoporporate image.module functionality into a module.
I got it working and thought I would share it here in case anyone else is trying to do this. This solution requires under 50 lines of code and will ignore the image functionality if image.module is not enabled on the site.
Step 1. hook_form
Add this code into your hook_form function.
// image form code
if(function_exists('_image_check_settings')){
_image_check_settings();
$param['options'] = array("enctype" => "multipart/form-data");
if (is_array($node->images)) {
foreach ($node->images as $label => $image) {
$output .= form_hidden('images]['.$label, $image);
}
}
if ($node->images['thumbnail']) {
$output.= form_item(t('Thumbnail'), image_display($node, 'thumbnail'));
}
$output .= form_file(t('Image'), 'image', 50, t('Click "Browse..." to select an image to upload.'), TRUE);
}
Step 2. hook_insert
First, you will need to change hook_insert($node) to hook_insert(&$node). This is because image_validate acts on the $node object and if you do not import the reference to the actual $node object via the '&' prefix, these changes will be lost. After this change has been made, add this code:
// image insert code (remember that image.module acts on $node to create $node->images)