Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/quickthumb.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ qt.static = function(root, options){

return sendfile(res, file);
});

// Either callback or sendfile has been called so we are done.
return;
}

callback();
});
});
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,8 @@
"dependencies": {
"imagemagick": "git://github.com/rsms/node-imagemagick.git",
"mkdirp": "~0.3.3"
},
"devDependencies": {
"express": "^4.13.3"
}
}
Binary file added public/images/cape cod modified.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 52 additions & 7 deletions test/express-test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
var express = require('express'),
app = express(),
qt = require('../'),
filename = 'cape cod.jpg';
app = express(),
qt = require('../'),
os = require('os'),
path = require('path'),
fs = require('fs'),

filename = 'cape cod.jpg',
publicDir = path.join(__dirname, '../public'),
imageDir = path.join(publicDir, 'images')
cacheDir = path.join(os.tmpdir(), 'quickthumb/cache');


// Crop
app.use('/public/crop', qt.static(__dirname + '/../public', {
cacheDir : '/tmp/cache',
app.use('/public/crop', qt.static(publicDir, {
cacheDir : cacheDir,
quality : .95
}));
// Resize
app.use('/public/resize', qt.static(__dirname + '/../public', {
app.use('/public/resize', qt.static(publicDir, {
type : 'resize',
}));

Expand All @@ -31,10 +38,48 @@ app.get('/', function(req, res){
});
h += '<br />' + img(type, '?dim=800x100') + '<br />';
});
h += '<br />original<br />' + img('crop','') + '</center>';
h += '<br />original<br />' + img('crop','') + '<br />';

// --- Image cache test
h += '<br />cache test<br /><img src="/test/1" id="cacheTest" /><br />'
+ '<br /><input type="button" onclick="next()" value="Modify"/>'
+ '<script>function next(){document.getElementById("cacheTest").src="/test/"+ ++t}var t=1;</script>';

h += '</center>';

res.send(h);
});

// --- Image cache test
var cacheTestImage = 'cache_test.jpg';
var modifiedImage = 'cape cod modified.jpg';
var redirectPath = '/public/crop/images/' + cacheTestImage
+ '?dim=x200&' + new Date().getTime();

app.get('/test/:step', function(req, res) {
switch (req.params.step) {
case '1': // Step 1: No cache, image has to be generated

// Create image for cache test
fs.createReadStream(path.join(imageDir, filename)).pipe(
fs.createWriteStream(path.join(imageDir, cacheTestImage)));

// Cached version is deleted so that it has to be generated
fs.unlink(path.join(cacheDir, 'crop/x200/images', cacheTestImage),
function(){/* ignore errors */});
break;

case '2': // Step 2: Image has to be regenerated since it was modified

// File is modifed so the cached version should be updated
fs.createReadStream(path.join(imageDir, modifiedImage)).pipe(
fs.createWriteStream(path.join(imageDir, cacheTestImage)));
break;

}

res.redirect(redirectPath);
});

app.listen(3000);
console.log("running on http://127.0.0.1:3000");