Not sure if this has been discussed other places (I took a quick look and didn't see anything), but I think it would be handy to have a way to use the power of the image module when coding new node types. A few times, I have found myself wishing for an easy way to attach an image node to another new custom node type. For example, when building a form in a new module, it would be really nice to be able to use a function similar to:
$output .= form_image_file($title, $name, $size, $max_image_size = NULL, $description = NULL, $required = FALSE);
I'm not sure how it would work exactly, but when a form containing the above code is submitted (or previewed), calls would be made automatically to the image.module to upload, resize, and handle the details of processing the image, and the node id of the new image would be returned.
Any thoughts?...
Comments
Comment #1
zach harkey commentedThis exact issue has come up over at flexinode. It looks like what we need is for the image module to provide some api-like functions. Other modules really need to be able to take advantage of the image module instead of having to implement their own mechanism for creating images.
Cvbge wrote:
Comment #2
walkah commentedyes robrecthtj and I have had some discussions about this...
the problem is this : a form_* function wouldn't be of any use.. because right now our form functions are just glorified theme functions (i.e. they only handle rendering the form) - thus your image upload function is just a form_file(). the big thing you want here is handling the file *after* upload. perhaps adrian's form api will help us here.
until then...
what do you want from such an API? because you already have things like image_scale and image_resize , that's all part of image.inc. the only real thing that image.module does special (besides some gallery features) is to keep a set of derivatives for each upload. however, if you just want an image file, you may (or may not) want a bunch of derivatives for that file - and you likely want a different set of derivatives, etc. there currently isn't a great way to handle all the settings for that... this is the one place where i think CCK is the answer - i.e. image as field type (rather than node).
Comment #3
moshe weitzman commentedi do this already in some modules. as mentioned you have to add code for the form. in addition , you need to call image_validate() in yoiur validate function and image_load in your load.
i found that images will be added with no further code but changes to those images required some code in my hook_update(). album.module uses image.module in this manner.
Comment #4
seanbfuller commentedI was playing around with this and posted my results here:
http://drupal.org/node/30944
It's a bit jumbled, but I was trying to walk through the process of adding all the necessary code.
Comment #5
guardian commentedSince Drupal 5.0, it is possible to add any field to any node, and "an easy way to add images to other node types" would be the use of the http://drupal.org/project/imagefield module.