Openseadragon: Server-side DZI Creation

Created on 2 Nov 2016  路  4Comments  路  Source: openseadragon/openseadragon

Excuse me for creating a new post on this topic. I spent a while with a server-side solution for creating dynamic deep-zoom images but ran into numerous problems due to the complexity of fast-cgi configurations on Linux, etc--at least for me.

Therefore, I now believe the simplest solution is to post a high-res image onto a server (zipped if TIF), run VIPS (server side) where it builds a DZI folder on some server or storage device. I want to build a solution that has step-by-step instructions so anyone can set up an AWS instance where they can easily create DZI repositories for their images, which they can call from their website (like digitiler.com in my case).

Before I embark on this, any ideas of code, libraries to use, things to think about, etc., would be appreciated! Or if you have any code, which you'd like to share?

Functions would be

  1. Upload full-res image
  2. Set VIPS (DZI) settings
  3. Set target DZI folders path ... Process ...
  4. Test DZI after creation
  5. Delete DZI path (if needed)

  6. Instruction on how to track costs through AWS of image bandwidth usage, etc.

question

All 4 comments

Hi there,

I have done a similar thing for a project recently. I wrote a simple batch-script that can do 2 - 5. After doing this for a while, I found that I could way better use Openslide. This means that you won't have to generate DZI tilemaps beforehand, as they will be generated dynamically. Installing Openslide, openslide-python (and of course python) and executing the example provided in deepzoom/examples/deepzoom_multiserver.py is enough to have a server goin'.

Other than that, if you still want to go with vips dzsave, I would say: good bet :+1: Vips is one of the best around imho, and FYI uses openslide libraries to read all kinds of TIFF formats.

~Koen

I don't have any specific advice, but it sounds like a good plan. If you end up open sourcing it (or if your service exposes an API), I'd love to add it here:

http://openseadragon.github.io/examples/creating-zooming-images/

Sorry I don't have time to pretty-up, still working on it, but things so crazy afraid i won't get back. So if anyone needs a simple PHP where they can upload a zipped dzi set (like vips dzsave myimage.jpg mydzi.zip) then this works:

```php
/* Simple script to upload a zip file to the webserver and have it unzipped
Saves tons of time, think only of uploading Wordpress to the server
Thanks to c.bavota (www.bavotasan.com)
I have modified the script a little to make it more convenient
Modified by: Johan van de Merwe (12.02.2013)
*/

$username = "user";
$password = "pw123";
$nonsense = "supercalifragilisticexpialidocious";

if (isset($_COOKIE['PrivatePageLogin'])) {
if ($_COOKIE['PrivatePageLogin'] == md5($password.$nonsense)) {

?>

function rmdir_recursive($dir) {
foreach(scandir($dir) as $file) {
if ('.' === $file || '..' === $file) continue;
if (is_dir("$dir/$file")) rmdir_recursive("$dir/$file");
else unlink("$dir/$file");
}

rmdir($dir);
}

if($_FILES["zip_file"]["name"]) {
$filename = $_FILES["zip_file"]["name"];
$source = $_FILES["zip_file"]["tmp_name"];
$type = $_FILES["zip_file"]["type"];

$name = explode(".", $filename);
$accepted_types = array('application/zip', 'application/x-zip-compressed', 'multipart/x-zip', 'application/x-compressed');
foreach($accepted_types as $mime_type) {
    if($mime_type == $type) {
        $okay = true;
        break;
    } 
}

$continue = strtolower($name[1]) == 'zip' ? true : false;
if(!$continue) {
    $message = "The file you are trying to upload is not a .zip file. Please try again.";
}

/* PHP current path */
$path = dirname(__FILE__).'/'; // absolute path to the directory where zipper.php is in
$filenoext = basename ($filename, '.zip'); // absolute path to the directory where zipper.php is in (lowercase)
$filenoext = basename ($filenoext, '.ZIP'); // absolute path to the directory where zipper.php is in (when uppercase)

$targetdir = $path . $filenoext; // target directory
$targetzip = $path . $filename; // target zip file

/* create directory if not exists', otherwise overwrite /
/
target directory is same as filename without extension */

if (is_dir($targetdir)) rmdir_recursive ( $targetdir);

mkdir($targetdir, 0777);

/* here it is really happening */

if(move_uploaded_file($source, $targetzip)) {
    $zip = new ZipArchive();
    $x = $zip->open($targetzip);  // open the zip file to extract
    if ($x === true) {
        $zip->extractTo($targetdir); // place in the directory with same name  
        $zip->close();

        unlink($targetzip);
    }
    $message = "Your .zip file was uploaded and unpacked.";
} else {    
    $message = "There was a problem with the upload. Please try again.";
}

}

?>




Unzip create DZI folder


$message

"; ?>




exit;
} else {
echo "Bad Cookie.";
exit;
}
}

if (isset($_GET['p']) && $_GET['p'] == "login") {
if ($_POST['user'] != $username) {
echo "Sorry, that username does not match.";
exit;
} else if ($_POST['keypass'] != $password) {
echo "Sorry, that password does not match.";
exit;
} else if ($_POST['user'] == $username && $_POST['keypass'] == $password) {
setcookie('PrivatePageLogin', md5($_POST['keypass'].$nonsense));
header("Location: $_SERVER[PHP_SELF]");
} else {
echo "Sorry, you could not be logged in at this time.";
}
}
?>



'''

Beautiful! Thank you for sharing this :)

Was this page helpful?
0 / 5 - 0 ratings