Commit 155a4be5 authored by Thomas Marrinan's avatar Thomas Marrinan

fixed #2 - tiff images now convert to png on the fly for rendering. more formats coming soon


Former-commit-id: 83846c35a237ae3285f18056c892a09f71cc57f8
parent 7c1048d0
......@@ -11,6 +11,7 @@
var decompresszip = require('decompress-zip');
var ffprobe = require('node-ffprobe');
var fs = require('fs');
var gm = require('gm');
var imageinfo = require('imageinfo');
var mime = require('mime');
var path = require('path');
......@@ -32,8 +33,9 @@ function appLoader(publicDir, hostOrigin, displayWidth, displayHeight, titleBarH
this.titleBarHeight = titleBarHeight;
this.mime2app = {
"image/jpeg": "image_viewer",
"image/png": "image_viewer",
"video/mp4": "movie_player",
"image/png": "image_viewer",
"image/tiff": "image_viewer",
"video/mp4": "movie_player",
"video/youtube": "movie_player",
"application/pdf": "pdf_viewer",
"application/zip": "custom_app",
......@@ -76,37 +78,10 @@ appLoader.prototype.loadImageFromURL = function(url, mime_type, name, strictSSL,
if(err) throw err;
var info = imageinfo(body);
var source = body.toString("base64");
var aspectRatio = info.width / info.height;
var appInstance = {
id: null,
title: name,
application: "image_viewer",
type: mime_type,
url: url,
data: {
src: source,
type: info.mimeType
},
resrc: null,
left: _this.titleBarHeight,
top: 1.5*_this.titleBarHeight,
width: info.width,
height: info.height,
native_width: info.width,
native_height: info.height,
previous_left: null,
previous_top: null,
previous_width: null,
previous_height: null,
maximized: false,
aspect: aspectRatio,
animation: false,
date: new Date()
};
_this.scaleAppToFitDisplay(appInstance);
callback(appInstance);
_this.loadImageFromDataBuffer(body, info.width, info.height, mime_type, url, url, name, function(appInstance) {
callback(appInstance);
});
});
};
......@@ -209,45 +184,67 @@ appLoader.prototype.loadPdfFromURL = function(url, mime_type, name, strictSSL, c
};
appLoader.prototype.loadImageFromDataBuffer = function(buffer, width, height, mime_type, url, external_url, name, callback) {
var source = buffer.toString("base64");
var aspectRatio = width / height;
var appInstance = {
id: null,
title: name,
application: "image_viewer",
type: mime_type,
url: external_url,
data: {
src: source,
type: mime_type
},
resrc: null,
left: this.titleBarHeight,
top: 1.5*this.titleBarHeight,
width: width,
height: height,
native_width: width,
native_height: height,
previous_left: null,
previous_top: null,
previous_width: null,
previous_height: null,
maximized: false,
aspect: aspectRatio,
animation: false,
date: new Date()
};
this.scaleAppToFitDisplay(appInstance);
callback(appInstance);
};
appLoader.prototype.loadImageFromFile = function(file, mime_type, url, external_url, name, callback) {
var _this = this;
fs.readFile(file, function (err, data) {
if(err) throw err;
var info = imageinfo(data);
var source = data.toString("base64");
var aspectRatio = info.width / info.height;
var appInstance = {
id: null,
title: name,
application: "image_viewer",
type: mime_type,
url: external_url,
data: {
src: source,
type: info.mimeType
},
resrc: null,
left: _this.titleBarHeight,
top: 1.5*_this.titleBarHeight,
width: info.width,
height: info.height,
native_width: info.width,
native_height: info.height,
previous_left: null,
previous_top: null,
previous_width: null,
previous_height: null,
maximized: false,
aspect: aspectRatio,
animation: false,
date: new Date()
};
_this.scaleAppToFitDisplay(appInstance);
callback(appInstance);
});
if(mime_type === "image/jpeg" || mime_type === "image/png"){
fs.readFile(file, function (err, data) {
if(err) throw err;
var info = imageinfo(data);
_this.loadImageFromDataBuffer(data, info.width, info.height, mime_type, url, external_url, name, function(appInstance) {
callback(appInstance);
});
});
}
else{
gm(file).noProfile().setFormat("PNG").toBuffer(function (err, buffer) {
if(err) throw err;
gm(buffer).size(function (err, size) {
if(err) throw err;
_this.loadImageFromDataBuffer(buffer, size.width, size.height, mime_type, url, external_url, name, function(appInstance) {
callback(appInstance);
});
});
});
}
};
appLoader.prototype.loadVideoFromFile = function(file, mime_type, url, external_url, name, callback) {
......
......@@ -841,7 +841,7 @@ function setupDisplayBackground() {
tmpImg = path.join(public_https, "images", "background", "tmp_background.png");
var out_res = config.totalWidth.toString() + "x" + config.totalHeight.toString();
gm(bg_file).command("convert").in("-gravity", "center").in("-background", "rgba(255,255,255,255)").in("-extent", out_res).write(tmpImg, function(err) {
gm(bg_file).noProfile().command("convert").in("-gravity", "center").in("-background", "rgba(255,255,255,255)").in("-extent", out_res).write(tmpImg, function(err) {
if(err) throw err;
sliceBackgroundImage(tmpImg, bg_file);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment