This allows anyone to upload a image file via FTP and a "Image" node is created automatically from it. It was developed as internal company project where the UI team can take screenshots of their design and let other comment on it, tag it, etc.

Demo : http://www.youtube.com/watch?v=E8snwivQxgY

Note : This involves hacking the Image and Image import module.

Step 1 :
Enable the Image, Image Gallery and Image import modules.

Step 2 :
Importing the images from the FTP directory as image nodes in Drupal. This uses the _image_import_batch_op() function from the "Import image" module.

Need to add a small function to "Import image" module.

File : image/contrib/image/image_import/image_import.module

Add the following lines to the end of the file :

function image_import_init() {
  /**** Replace this with the path of the FTP Image direcectory ****/
  $upload_dir = "/var/www/html/ps/sites/default/files/uploads/";
  include("image_import.pages.inc");
  $directory_handle = opendir($upload_dir);
  while (($filename = readdir($directory_handle)) !== false)
  {
    /* If filename is a directory ignore */
    if (filetype($upload_dir . $filename) == 'dir')
      continue;

    /* check valid image */
    $filename_arr = explode(".", $filename);
    $filename_ext = $filename_arr[sizeof($filename_arr) -1 ];
    if (!preg_match('/^(gif|png|jpg|jpeg)$/i', $filename_ext))
    {
     if (unlink($upload_dir . $filename))
      drupal_set_message("Removed invalid image file : " . $filename);
      continue;
    }

    $args['node_type'] = 'image';
    $args['title'] = $filename;
    $args['filepath'] = $upload_dir . $filename;
    $args['origname'] = $filename;
    $args['subgallery'] = 0;
    _image_import_batch_op($args, $context);
    drupal_set_message("Added image " . $filename);
  }
  closedir($directory_handle);
}
/******* end ********/

Step 3 (optional) :
Change the default ownership of Image content type to anonymous user. And later allow anyone to claim the image.

File : image/image.module

Change the line no 1079 :
$node->uid = $user->uid;
$node->name = $user->name;
To :
$node->uid = 0;//$user->uid;
// $node->name = $user->name;

Step 4 :
Allowing people to own the image.

a) create a small module for that purpose.
Name of module : openpixel
Filename : openpixel.module

<?php
function openpixel_menu()
{
  $items = array();
  $items['node/%/own'] = array(
    'title' => 'Own the node',
    'description' => 'Change the user of the node to logged in user.',
    'page callback' => 'openpixel_nodeown',
    'page arguments' => array(1),
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );
  $items['node/%/release'] = array(
    'title' => 'Release the node',
    'description' => 'Change the user of the node to anonymous user.',
    'page callback' => 'openpixel_noderelease',
    'page arguments' => array(1),
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );
  return $items;
}

function openpixel_nodeown($node_id)
{
  global $user;
  $node_data = node_load($node_id);
  $user_id = $user->uid;

  if (!$node_data)
  {
    drupal_set_message("Invalid image selected", $type = 'warning');
    drupal_goto("node");
    return;
  }
  else
  {
    if (db_query("UPDATE {node} set uid = %d WHERE nid = %d", $user_id, $node_id) )
      drupal_set_message($node_data->title . " is now owned by " . $user->name, $type = 'status');
    else
      drupal_set_message("Error changing image ownership", $type = 'warning');
  }
  drupal_goto("node/" . $node_id);
  return;
}

function openpixel_noderelease($node_id)
{
  global $user;
  $node_data = node_load($node_id);
  $user_id = $user->uid;

  if (!$node_data)
  {
    drupal_set_message("Invalid image selected", $type = 'warning');
    drupal_goto("node");
    return;
  }
  else
  {
    if (db_query("UPDATE {node} set uid = 0 WHERE nid = %d", $node_id) )
      drupal_set_message($node_data->title . " is no longer owned by anyone", $type = 'status');
    else
      drupal_set_message("Error changing image ownership", $type = 'warning');
  }
  drupal_goto("node/" . $node_id);
  return;
}

b ) created links in the theme files
Filename : node.tpl.php

<?php
  global $user;
  if( ($user->uid) && ($node->type == 'image') )
  {
    if ($node->uid == $user->uid)
    {
      print '| ' . l('Release image', 'node/' . $node->nid . '/release');
    }
    else if ($node->uid == 0)
    {
      print '| ' . l('Claim image', 'node/' . $node->nid . '/own');
    }
  }
?>

It can be used with Image capture utilities like http://skitch.com/ (on mac) and http://code.google.com/p/zscreen/ (on windows)

Comments

funky2D’s picture

Hi,

I am interested to see the demo or a live website using this code.
Thanks in advance.