How to upload/insert images in content from module?
I have tried the below code with node_save method but not with entity_create way. Check if it works.

$dir = 'public://';
if (file_prepare_directory($dir, FILE_CREATE_DIRECTORY)) {
  $file = file_save_upload('image', array(), $dir, FILE_EXISTS_RENAME);
  $file-&gt;status = FILE_STATUS_PERMANENT;
  file_save($file);
  $attachment = array(
    'fid' =&gt; $file-&gt;fid,
    'display' =&gt; 1,
    'description' =&gt; $file-&gt;name,
    'title' =&gt; $values-&gt;tooltip
  );
}

$article = entity_create('node', array(
  'type' =&gt; 'article',
  'title' =&gt; generate_demo_content('lorem_ipsum_title'),
  'body' =&gt; array(
    'value' =&gt; generate_an_article(),
    'format' =&gt; 'full_html',
  ),
  'field_attachment' =&gt; $attachment, //may need to change here
));