How rad would it be if this module could grab the first image from a post body, download a copy locally and map that to the filefield. Drupal Feeds would be unstoppable.

Here is the string function I'm using to process the $content variable in the theme layer. This is nice, but I don't have a local copy and I can't run it through imagecache, etc.

function mymodule_catch_image($string) {
  $first_img = '';
  $output= preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $string, $matches);
  $first_img = $matches[1][0];

  if(empty($first_img)){ //Defines a default image
    $first_img = "/images/default.jpg";
  }
  return $first_img;
}

I'd love to incorporate this into the module, as I've wanted to accomplish this forever. I'll just need some guidance.

I'm still on the DrupalCon high, so catch me while I'm inspired :)

Comments

publicmind’s picture

Status: Active » Closed (works as designed)

IIUC, you are proposing FIG to process the content in the body field which is filled by the Feeds module to look for images. FIG is not designed to do so, it grabs image from the article page on the original site. You might want to look into:

http://drupal.org/project/feedapi_scraper
http://drupal.org/node/635520
http://drupal.org/project/querypath

FeedAPI scraper would do what you are trying to accomplish but unfortunately hasn't been ported for Feeds yet. It would be wonderful if you can help with its port. Consider me available for any help.

Regards,

doublejosh’s picture