Image resize with nginx (this is replace phpThumb script)
// Image resize with nginx (this is replace phpThumb script)
function escapeRegExp(str) {
return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
}
function replaceAll(str, find, replace) {
return str.replace(new RegExp(escapeRegExp(find), 'g'), replace);
}
function isEmpty(str) {
return (!str || 0 === str.length);
}
function js_get_uri_src_dirname(req, res) {
var src, decoded;
src = req.args["src"];
if(isEmpty(src)) {
decoded = "/s/images/no-photo.jpg";
} else {
decoded = decodeURIComponent(src);
}
var dirname = decoded.replace(/[^\\\/]*$/, '');
return dirname;
}
function js_get_image_uri(req, res) {
var uri, src, w, h, q, decoded, filename, dirname;
src = req.args["src"];
w = req.args["w"];
h = req.args["h"];
q = req.args["q"];
if(isEmpty(src)) {
decoded = "/s/images/no-photo.jpg";
} else {
src = replaceAll(src, "+", "%20");
decoded = decodeURIComponent(src);
}
filename = decoded.replace(/^.*[\\\/]/, '');
if(isEmpty(w)) {
w = "150";
}
if(isEmpty(h)) {
h = "150";
}
if(isEmpty(q)) {
q = "90";
}
dirname = decoded.replace(/[^\\\/]*$/, '');
uri = "image_resize/" + filename + "?width=" + w + "&height=" + h + "&path=" + dirname + "&quality=" + q;
return uri;
}
function js_get_image_filename(req, res) {
var image_filename, src, w, h, q, decoded, filename, dirname;
src = req.args["src"];
w = req.args["w"];
h = req.args["h"];
q = req.args["q"];
if(isEmpty(src)) {
decoded = "/s/images/no-photo.jpg";
} else {
src = replaceAll(src, "+", "%20");
decoded = decodeURIComponent(src);
}
filename = decoded.replace(/^.*[\\\/]/, '');
if(isEmpty(w)) {
w = "150";
}
if(isEmpty(h)) {
h = "150";
}
if(isEmpty(q)) {
q = "90";
}
dirname = decoded.replace(/[^\\\/]*$/, '');
image_filename = dirname + w + h + q + "_" + filename;
return image_filename;
}
function js_get_resized_image_filename(req, res) {
var resized_image_filename, src, w, h, q, decoded, filename, dirname;
src = req.args["src"];
w = req.args["w"];
h = req.args["h"];
q = req.args["q"];
if(isEmpty(src)) {
decoded = "/s/images/no-photo.jpg";
} else {
src = replaceAll(src, "+", "%20");
decoded = decodeURIComponent(src);
}
filename = decoded.replace(/^.*[\\\/]/, '');
if(isEmpty(w)) {
w = "150";
}
if(isEmpty(h)) {
h = "150";
}
if(isEmpty(q)) {
q = "90";
}
dirname = decoded.replace(/[^\\\/]*$/, '');
resized_image_filename = w + h + q + "_" + filename + "?path=" + dirname;
return resized_image_filename;
}