I am uploading files using my own script and want to pass of the file path to the function image_create_node_from(). I do this and get an image node created but none of the image derivatives get created. I got creative and exposed _image_build_derivatives() by copying it and simply renaming it exposed_image_build_derivatives(). This worked but it left the derivatives in files/images/temp. Alternatively I tried calling image_operations_rebuild() but that left the permissions on the images 655 (rw-r--r--), which is not useful for the web.
Here is my code:
function attach_images_form_submit($form_id, $form_values)
{
/* check in the args for the item id
$count = 0;
while($arg = arg($count))
{
print "Arg: $arg";
$count++;
}
*/
$item_id = arg(2);
//print "<pre>" . print_r($form_values, TRUE) . "</pre>";
$dir = variable_get('file_directory_path', NULL);
// we want to put them in files/images/import
$dir = $dir . "/images/import";
//print "Directory: $dir<br/>";
$is_writable = file_check_directory($dir, 1);
//print "Is Writable: $is_writable<br/>";
if($is_writable)
{
// loop through each of the upload items
foreach($form_values as $key=>$data)
{
//print "Key: $key<br/>";
if(strpos($key, 'upload') !== FALSE) // MAKE SURE WE ARE IN A KEY FOR AN UPLOAD
{
$source = file_check_upload($key);
// Security measure to prevent exploit of file.php.png
$source->filename = $item_id.".".upload_munge_filename($source->filename);
//print "<pre>" . print_r($source, TRUE) . "</pre>";
if ($file = file_save_upload($source,$dir ))
{
if(image_get_info($file->filepath))
{
//print "<pre>" . print_r($file, TRUE) . "</pre>";
$node = image_create_node_from($file->filepath);
// build our preview images/etc
exposed_image_build_derivatives($node, TRUE);
//image_operations_rebuild($node);
//drupal_set_message(t('New image saved.'));
// now we can create an image node from the filename
}
else
{
file_delete($file->filepath);
drupal_set_message('Uploaded file does not appear to be a valid image file. Please try again.');
}
}
}
}
}
}
Basically is there a function that I can call after I build the node to generate the derivatives?
Thanks!
Comments
Comment #1
sunSorry, unfortunately this request is way too specific. Please have a look at the issue queue - Image maintainers are buried already. You might want to try to get further support at http://drupal.org/support. Additionally, the answer to your question might be covered in the handbooks at http://drupal.org/handbook/modules/image already.
If you were able to solve this issue on your own in the meantime, you might want to add the involved steps to this closed issue, so other users searching for a similar solution might find it.