In the past days I've been searching for a module that allows users to upload images and associate them to a node. My requirements are:

  • easy image upload from the node edit area;
  • thumbnail creation;
  • overview of uploaded images, with editable descriptions and weight, and checkboxes to delete images;
  • show the uploaded images below the node body/teaser when viewing the node.

I've looked at different modules (upload.module in core, and many others in the cvs), but none of them really satisfied my needs:

  • upload.module works manages files as attachments to the node, it is not specific for images;
  • image.module is a good one, but I don't want images as nodes;
  • image_attach.module and upload_image.module depend on image.module and creates images as nodes;
  • image_tab.module is quite close to my needs, but it depends on image.module and creates images as nodes, anyway it was the main source for my inspiration.

I decided to create a new module, node_images.module, that does the above things in a very simple way. It adds an Images tab in the node page, providing a table view of the uploaded images, and below the upload form to add new images.
The node_images.module saves the images in the node_images table, it keeps the association of each image with its node and user. It requires the upload.module to be enabled, because it performs validation provided by upload module.
Each image has thumbnail, description, and weight; users can edit description and weight through the overview table.
The administration section allow admins to enable node images for specific content types, set allowed image extensions, and also set a maximum number of images for a node.
Admins can choose a directory to save node images, the directory path may also contain the variable %uid, so there will be a different folder for each user. For example, if the path is "files/%uid" there will be a files/1 directory for user#1, files/2 for user#2, files/3 for user#3, etc...
The attached zip file contains node_images.module and node_images.install

Comments

scroogie’s picture

Did you have a look at imagefield for CCK or img_assist for general textareas?
As for your new module, can you perhaps show a demonstration or do some screenshots?
thanks

stefano73’s picture

StatusFileSize
new66.27 KB

Those modules didn't fully fit my needs in a simple way.
Screenshot attached.

scroogie’s picture

Looks nice. Can the images be reused in other nodes? How are the images presented in the content view?

stefano73’s picture

StatusFileSize
new18.49 KB

The hook_nodeapi() "view" now searchs for a custom theme function for the current node type, so every node type can add a different image view to the node body.
If there's no node type function, the default theme function provided with node_images.module will be used. The default theme function shows the thumbs below the node body, and each thumb opens a popup with the original image.

stefano73’s picture

StatusFileSize
new150.81 KB

Screenshot of the node view with node images.

stefano73’s picture

StatusFileSize
new19.41 KB

Updated module to latest cvs.

webchick’s picture

Looks pretty cool, but it's after the code freeze, so this won't make it into core (if at all) before 5.1.

Have you tried applying for a CVS account? This way your module would be listed in the Drupal.org modules directory, where more people would see it, and you'd get an issue tracker to handle bug reports and feature requests.

mgrant’s picture

I tried to install the 1.1 version on 4.7 and I don't see anything when I go to create a new node.

When I go to administer->settings->node images, I get the following error:

warning: Missing argument 2 for drupal_get_form() in /example.com/docroot/includes/form.inc on line 61.

Any ideas?

stefano73’s picture

StatusFileSize
new20.38 KB

I made up my mind and installed Drupal 4.7.3, the attached file is a working version for 4.7.3.

I also added a setting in the admin section to select the image position with respect to node body:
- "above" (above node body);
- "below" (below node body, default choice);
- "node_template" (manually set in node template by variable $node->node_images);

stefano73’s picture

StatusFileSize
new9.31 KB

New version for the node_images.module. It works on the latest cvs. I added a photo gallery with a Polaroid css to show the images associated to the current node. You can see a demo node on my test site.

The attached zip file is the package with the module and the other required files. I also added a node-example.tpl.php to show how to manually configure the node images in the node template, so you can override the default setting that puts images right below the node body.

Screenshots: Images edit page, Node view

dodorama’s picture

Trying to install your module in the latest cvs I had this error message:

user warning: Invalid default value for 'id' query: CREATE TABLE node_images ( id int(10) unsigned NOT NULL default '0' auto_increment, nid int(10) unsigned NOT NULL default '0', uid int(10) unsigned NOT NULL default '0', filename varchar(255) NOT NULL default '', filepath varchar(255) NOT NULL default '', filemime varchar(255) NOT NULL default '', filesize int(10) unsigned NOT NULL default '0', thumbpath varchar(255) NOT NULL default '', thumbsize int(10) unsigned NOT NULL default '0', status tinyint(1) unsigned NOT NULL default '1', weight tinyint(1) NOT NULL default '0', description varchar(255) default NULL, PRIMARY KEY (id), KEY uid (uid), KEY nid_status (nid,status) ) /*!40100 DEFAULT CHARACTER SET UTF8 */ in /Applications/MAMP/htdocs/cvs/includes/database.mysql.inc on line 167.

Any idea of what happens?

stefano73’s picture

StatusFileSize
new9.31 KB

Mysql 5.x doesn't accept default values for autoincrement fields (4.x does). Here is the new package with the updated install file.

dodorama’s picture

Still having troubles with it (no more errors on module installation but on node submission):

user warning: Table 'cvs.node_images' doesn't exist query: SELECT * FROM node_images WHERE nid=4 AND status=1 ORDER BY weight in /Applications/MAMP/htdocs/cvs/includes/database.mysql.inc on line 167.

It seems that the tables aren't installed.

stefano73’s picture

The table was not installed when you enabled the module because of the previous error. You should manually run the create table query on your database (you can find it in the .install file), I write it below:

CREATE TABLE node_images (
id int(10) unsigned NOT NULL auto_increment,
nid int(10) unsigned NOT NULL default '0',
uid int(10) unsigned NOT NULL default '0',
filename varchar(255) NOT NULL default '',
filepath varchar(255) NOT NULL default '',
filemime varchar(255) NOT NULL default '',
filesize int(10) unsigned NOT NULL default '0',
thumbpath varchar(255) NOT NULL default '',
thumbsize int(10) unsigned NOT NULL default '0',
status tinyint(1) unsigned NOT NULL default '1',
weight tinyint(1) NOT NULL default '0',
description varchar(255) default NULL,
PRIMARY KEY (id),
KEY uid (uid),
KEY nid_status (nid,status)
) /*!40100 DEFAULT CHARACTER SET UTF8 */

dodorama’s picture

Works now.

Thanks

coreb’s picture

Version: x.y.z » 4.7.x-dev

(Moving x.y.z version to a real version number)
It appears that you are working with 4.7, so I updated version to this.

I think this user needs to get a CVS account, and create a project rather than using this single issue for a

  • project node
  • release announcement
  • support thread

They will get much more exposure if they were to do this.

This appears to be improper use of the issue queue.

magico’s picture

Version: 4.7.x-dev » 6.x-dev
Component: other » upload.module
Category: task » feature
Status: Active » Closed (duplicate)

Feature requests go into 6.x-dev

Marking this as duplicate, because this "new" module features are similar to the ones I propose here http://drupal.org/node/25685#comment-177073

So, I ask stefano73 if he wants (and has time) to work on the issue above.

datatect’s picture

Version: 6.x-dev » 5.1
Component: upload.module » other
Category: feature » bug
Priority: Normal » Critical
Status: Closed (duplicate) » Active

server: php5, apache2.2, linux Ubuntu, drupal 5.1

i wgetted and activated node_images module. i get this:

Fatal Error: syntax error, unexpected $end in /var/www/drupal/modules/node_images/node_images.module on line 891

looked around, found a php hack at: http://drupal.org/node/119753
didn't do it for me.

upload.module is activated. gdlib and imagekmagick apt-getted long ago.

can i simply drop the entire node_images table with phpmyadmin?
and remove the node_images module from my drupal installation??

help.

drewish’s picture

Version: 5.1 » 6.x-dev
Component: other » upload.module
Status: Active » Closed (duplicate)

datatect, you really shouldn't be using this module, try something else.

yusuf_cse’s picture

Version: 6.x-dev » 5.1
Component: upload.module » other
Assigned: Unassigned » yusuf_cse

Node_images can upload jpg extension image. But is it capable upload gif extension image in thumbnail format? Same for png image. If it is possible, how?
Plz reply any body quickly.

romunov’s picture

I'm trying to make the images in my gallery centered. The first image is centered fine and dandy, but the next image I select is shifted to the left (see here). Can I align them with styles or with php, and how?

Best wishes,
Roman

romunov’s picture

I've solved the problem. I created a class ni node_images.css like so:

#center_image {
	margin: 0 auto;   /* align for good browsers */
	text-align: left; /* counter the body center */
	width: 70%;
}

And added a

at roughly line 662 in the node_images.module:
<div id="center_image"><img src="'. url($element['#image']['src']) .'" class="polaroid" /></div>

Does anyone have a better and/or more elegant solution?