Browse Source

added ingest to basic image types using a default mods form

pull/120/merge
Paul Pound 13 years ago
parent
commit
13825faf5f
  1. 1
      includes/datastream.inc
  2. 2
      includes/islandora.ingest.inc
  3. 39
      islandora_basic_image/includes/image_process.inc
  4. 19
      islandora_basic_image/islandora_basic_image.module

1
includes/datastream.inc

@ -32,6 +32,7 @@ function islandora_datastream_as_attachment($object_id, $dsid) {
if (isset($method) && $method == 'download') { if (isset($method) && $method == 'download') {
header("Content-Disposition: attachment; filename=\"" . $fedora_object[$dsid]->label); header("Content-Disposition: attachment; filename=\"" . $fedora_object[$dsid]->label);
} }
//maybe able to use drupal's file transfer here
print($fedora_object[$dsid]->content); print($fedora_object[$dsid]->content);
exit(); exit();
} }

2
includes/islandora.ingest.inc

@ -21,7 +21,7 @@ function islandora_ingest_get_object($content_models, $collection_pid, $relation
} }
function islandora_ingest_add_object(&$object) { function islandora_ingest_add_object(&$object) {
$object->repository->ingestObject($object); //$object->repository->ingestObject($object);
module_invoke_all('islandora_ingest_post_ingest', $object); module_invoke_all('islandora_ingest_post_ingest', $object);
return $object; return $object;
} }

39
islandora_basic_image/includes/image_process.inc

@ -0,0 +1,39 @@
<?php
/**
*
* @param object $file
* stdclass
*/
function islandora_basic_image_create_derivative($file, $width, $height) {
$real_path = drupal_realpath($file->uri);
$image = image_load($real_path);
if (!empty($image)) {
$scale = image_scale($image, $width, $height, TRUE);
if($scale){
return image_save($image);
}
}
return FALSE;
}
/**
* adds a datastream and deletes the tmp file from local file system
* @param object $object
* @param string $dsid
* @param object $file
*/
function islandora_basic_image_add_datastream($object, $dsid, $file) {
try {
$ds = $object->constructDatastream($dsid, 'M');
$ds->label = $dsid;
$ds->mimeType = $object['OBJ']->mimeType;
$ds->setContentFromFile(drupal_realpath($file->uri));
$object->ingestDatastream($ds);
file_delete($file);
} catch (exception $e) {
drupal_set_message(t('@message', array('@message' => check_plain($e->getMessage()))), 'error');
}
}

19
islandora_basic_image/islandora_basic_image.module

@ -193,6 +193,25 @@ function islandora_basic_image_islandora_view_object($object, $user, $page_numbe
return NULL; return NULL;
} }
function islandora_basic_image_islandora_ingest_post_ingest($object) {
module_load_include('inc', 'islandora', 'includes/MimeClass');
module_load_include('inc', 'islandora_basic_image','includes/image_process');
$mime_class = new MimeClass();
$ext = $mime_class->getExtension($object['OBJ']->mimeType);
$file_name = str_replace(':', '-', $object->id);
$original_file = file_save_data($object['OBJ']->content, 'temporary://' . $file_name . 'OBJ.' . $ext);
$tn_file = file_copy($original_file, 'temporary://' . $file_name . 'TN.' . $ext);
if(islandora_basic_image_create_derivative($tn_file, 200, 200)){
islandora_basic_image_add_datastream($object, 'TN', $tn_file);
}
$medium_file = file_copy($original_file, 'temporary://' . $file_name . 'MEDIUM.' . $ext);
if(islandora_basic_image_create_derivative($medium_file, 500, 700)){
islandora_basic_image_add_datastream($object, 'MEDIUM_SIZE', $medium_file);
}
}
/** /**
* *
* @global type $base_url * @global type $base_url

Loading…
Cancel
Save