You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
119 lines
3.9 KiB
119 lines
3.9 KiB
14 years ago
|
<?php
|
||
14 years ago
|
|
||
13 years ago
|
/**
|
||
|
* fedora imageapi menu
|
||
|
* @return string
|
||
|
*/
|
||
14 years ago
|
function fedora_imageapi_menu() {
|
||
|
$items = array();
|
||
|
$items['fedora/imageapi'] = array(
|
||
|
'title' => t('Image manipulation functions'),
|
||
|
'page callback' => 'fedora_repository_image_manip',
|
||
|
'type' => MENU_CALLBACK,
|
||
|
'access arguments' => array('view fedora collection'),
|
||
|
);
|
||
|
return $items;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Call out to the Drupal ImageAPI module and return the resulting image as a stream.
|
||
|
*
|
||
|
* @param string $pid
|
||
|
* @param string $dsid
|
||
|
* @param string $op
|
||
|
* @param string $params
|
||
|
*/
|
||
|
function fedora_repository_image_manip($pid = '', $dsid = '', $op = '', $params = '') {
|
||
14 years ago
|
module_load_include('inc', 'Fedora_Repository', 'ObjectHelper');
|
||
|
module_load_include('module', 'imageapi');
|
||
14 years ago
|
$obj = new ObjectHelper();
|
||
14 years ago
|
$mimetype = $obj->getMimeType($pid, $dsid);
|
||
|
$ext = substr(strstr($mimetype, '/'), 1);
|
||
14 years ago
|
$op = (!empty($_GET['op']) ? $_GET['op'] : '');
|
||
|
$safe_pid = str_replace(':', '_', $pid);
|
||
14 years ago
|
|
||
|
$cache_key = 'fedora_repository_image_manip_' . md5($safe_pid . '_' . $dsid . '_' . $ext . '_' . $op . (isset($_GET['width']) ? '_' . $_GET['width'] : '') . (isset($_GET['height']) ? '_' . $_GET['height'] : ''));
|
||
|
if (($file = cache_get($cache_key)) === 0) {
|
||
14 years ago
|
//added the slash as sys_get_temp_dir in linux does not seem to include the slash
|
||
14 years ago
|
$tmp_file_name = sys_get_temp_dir() . '/' . $safe_pid . '_' . $dsid . '.' . $ext;
|
||
|
$handle = fopen($tmp_file_name, "w");
|
||
14 years ago
|
$numbytes = fwrite($handle, $obj->getStream($pid, $dsid));
|
||
|
fclose($handle);
|
||
|
if ($numbytes == 0) {
|
||
|
return;
|
||
|
}
|
||
14 years ago
|
|
||
|
|
||
|
$image = imageapi_image_open($tmp_file_name);
|
||
|
|
||
14 years ago
|
switch ($op) {
|
||
|
case 'scale':
|
||
14 years ago
|
if (!empty($_GET['height']) || !empty($_GET['width'])) {
|
||
|
imageapi_image_scale($image, $_GET['width'], $_GET['height']);
|
||
|
}
|
||
|
case 'centerscale':
|
||
|
if (!empty($_GET['height']) && !empty($_GET['width'])) {
|
||
|
imageapi_image_scale_and_crop($image, $_GET['width'], $_GET['height']);
|
||
|
}
|
||
14 years ago
|
}
|
||
|
imageapi_image_close($image);
|
||
|
$file = file_get_contents($tmp_file_name);
|
||
14 years ago
|
cache_set($cache_key, $file, 'cache', time() + variable_get('fedora_image_blocks_cache_time', 3600));
|
||
14 years ago
|
file_delete($tmp_file_name);
|
||
14 years ago
|
}
|
||
|
else {
|
||
14 years ago
|
$file = $file->data;
|
||
|
}
|
||
14 years ago
|
|
||
14 years ago
|
|
||
|
header("Content-type: $mimetype");
|
||
14 years ago
|
header('Content-Disposition: attachment; filename="' . $dsid . '.' . $ext . '"');
|
||
14 years ago
|
echo $file;
|
||
14 years ago
|
|
||
|
|
||
14 years ago
|
// return "$numbytes bytes written to ".sys_get_temp_dir()."$pid_$dsid.$ext\n";
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Implementation of hook_form_alter
|
||
|
*
|
||
|
* @param unknown_type $form
|
||
|
* @param unknown_type $form_state
|
||
|
* @param unknown_type $form_id
|
||
|
*/
|
||
14 years ago
|
/*
|
||
|
function fedora_imageapi_form_alter( &$form, $form_state, $form_id) {
|
||
|
|
||
14 years ago
|
switch ( $form_id ) {
|
||
14 years ago
|
case 'fedora_repository_admin':
|
||
|
|
||
|
$fedora_base_url = $form['fedora_base_url']['#default_value'];
|
||
|
|
||
|
$fedora_server_url = substr($fedora_base_url,0,strpos($fedora_base_url,'/',7));
|
||
|
// Add the Djatoka server location. Set it to default to the same server as fedora.
|
||
|
$form['djatoka_server_url'] = array (
|
||
|
'#type' => 'textfield',
|
||
|
'#title' => '<h3>'.t('Fedora Image API Module').'</h3><br />'.t('aDORe Djatoka image server resolver URL'),
|
||
|
'#default_value' => variable_get('djatoka_server_url', $fedora_server_url.'/adore-djatoka/resolver' ),
|
||
|
'#description' => t('The location of your <a href="http://african.lanl.gov/aDORe/projects/djatoka/" title="aDORe Djatoka Home Page">aDORe Djatoka</a> image server, if you have one installed.'),
|
||
|
'#weight' => 1,
|
||
|
);
|
||
|
$form['openlayers_server_url'] = array(
|
||
|
'#type' => 'textfield',
|
||
|
'#title' => t('OpenLayers servlet URL'),
|
||
|
'#default_value' => variable_get('openlayers_server_url', $fedora_server_url.'/islandora/OpenLayers'),
|
||
|
'#description' => t('URL of your installation of the <a href="http://openlayers.org/">OpenLayers</a> servlet, if you have one.'),
|
||
|
'#weight' => 1,
|
||
|
);
|
||
|
$form['buttons']['#weight'] = 2;
|
||
|
break;
|
||
|
}
|
||
14 years ago
|
}
|
||
|
|
||
14 years ago
|
function show_openlayers_viewer() {
|
||
14 years ago
|
$output = 'Hi.';
|
||
14 years ago
|
|
||
14 years ago
|
return $output;
|
||
14 years ago
|
}
|
||
|
*/
|