mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-18 16:13:24 +02:00
Add an app for resizing images. Still needs rate limiting, and still trying to decide how to pass the correct URL to the app.
This commit is contained in:
19
lib/roles/storage/plugins/image/task/get.js
Normal file
19
lib/roles/storage/plugins/image/task/get.js
Normal file
@@ -0,0 +1,19 @@
|
||||
var util = require('util')
|
||||
var http = require('http')
|
||||
|
||||
var Promise = require('bluebird')
|
||||
|
||||
module.exports = function(id, options) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
http.get(util.format('%sapi/v1/resources/%s', options.storageUrl, id))
|
||||
.on('response', function(res) {
|
||||
if (res.statusCode !== 200) {
|
||||
reject(new Error(util.format('HTTP %d', res.statusCode)))
|
||||
}
|
||||
else {
|
||||
resolve(res)
|
||||
}
|
||||
})
|
||||
.on('error', reject)
|
||||
})
|
||||
}
|
||||
26
lib/roles/storage/plugins/image/task/transform.js
Normal file
26
lib/roles/storage/plugins/image/task/transform.js
Normal file
@@ -0,0 +1,26 @@
|
||||
var gm = require('gm')
|
||||
var Promise = require('bluebird')
|
||||
|
||||
module.exports = function(stream, options) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var transform = gm(stream)
|
||||
|
||||
if (options.gravity) {
|
||||
transform.gravity(options.gravity)
|
||||
}
|
||||
|
||||
if (options.crop) {
|
||||
transform.geometry(options.crop.width, options.crop.height, '^')
|
||||
transform.crop(options.crop.width, options.crop.height, 0, 0)
|
||||
}
|
||||
|
||||
transform.stream(function(err, stdout) {
|
||||
if (err) {
|
||||
reject(err)
|
||||
}
|
||||
else {
|
||||
resolve(stdout)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user