Permalink
Browse files

Support delay

  • Loading branch information...
1 parent 4a50639 commit 7b4f4b228fc6e60a325d0889962dedce017c7576 @francoislg committed Dec 11, 2016
Showing with 24 additions and 16 deletions.
  1. +8 −0 README.md
  2. BIN baseparrots/parrot.gif
  3. +13 −13 index.js
  4. +3 −3 src/ParrotConstructor.js
View
@@ -29,3 +29,11 @@ To solve this problem, it is possible to adjust it the overlay with the followin
https://ppaas.herokuapp.com/partyparrot?overlay=http://i.imgur.com/QJ41dQb.png&overlayWidth=15&overlayHeight=15&overlayOffsetX=-7&overlayOffsetY=-3
Here is the result: ![Upvote Party Parrot](https://ppaas.herokuapp.com/partyparrot?overlay=http://i.imgur.com/QJ41dQb.png&overlayWidth=15&overlayHeight=15&overlayOffsetX=-7&overlayOffsetY=-3 "Upvote Party Parrot")
+
+## Delay
+
+You can adjust the delay between frames using the delay query parameter:
+
+https://ppaas.herokuapp.com/partyparrot?delay=20
+
+Here is the result: ![Fast Parrot](https://ppaas.herokuapp.com/partyparrot?delay=20 "Fast Parrot")
View
Deleted file not rendered
View
@@ -5,22 +5,22 @@ const request = require("request-promise");
var app = express();
-app.all("/partyparrot", (req, res, next) => {
- console.log("request received");
- next();
+app.get("/partyparrot", (req, res, done) => {
+ handleRequest(res, req.query);
});
-app.get("/partyparrot", (req, res, done) => {
- let fileName = "test.gif";
+function handleRequest(res, queryParams) {
+ let fileName = "generatedparrot.gif";
res.writeHead(200, { "Content-Type":"image/gif" });
- let parrotConstructor = new ParrotConstructor(res);
+
+ let parrotConstructor = new ParrotConstructor(res, queryParams);
var promises = [];
- if(req.query.overlay) {
- var overlayPromise = parrotConstructor.addFollowingOverlayImage(req.query.overlay,
- parseInt(req.query.overlayOffsetX),
- parseInt(req.query.overlayOffsetY),
- req.query.overlayWidth,
- req.query.overlayHeight);
+ if(queryParams.overlay) {
+ var overlayPromise = parrotConstructor.addFollowingOverlayImage(queryParams.overlay,
+ parseInt(queryParams.overlayOffsetX),
+ parseInt(queryParams.overlayOffsetY),
+ queryParams.overlayWidth,
+ queryParams.overlayHeight);
promises.push(overlayPromise);
}
if (promises.length > 0) {
@@ -32,6 +32,6 @@ app.get("/partyparrot", (req, res, done) => {
} else {
parrotConstructor.finish();
}
-});
+}
app.listen(process.env.PORT || 8080);
@@ -4,7 +4,7 @@ const ParrotFrameHandler = require("./ParrotFrameHandler");
const ImageFactory = require("./ImageFactory");
const config = require("./config");
-function ParrotConstructor(writeStream, baseParrot, delay) {
+function ParrotConstructor(writeStream, parrotConstructorConfiguration) {
this.parrotFrameHandlers = [];
this.imageFactory = new ImageFactory();
@@ -13,9 +13,9 @@ function ParrotConstructor(writeStream, baseParrot, delay) {
this.encoder.start();
this.encoder.setTransparent("#000000");
this.encoder.setRepeat(0);
- this.encoder.setDelay(delay || 40);
+ this.encoder.setDelay(parrotConstructorConfiguration.delay || 40);
- this.setBaseParrot(baseParrot || "parrot");
+ this.setBaseParrot(parrotConstructorConfiguration.baseParrot || "parrot");
}
ParrotConstructor.prototype.setBaseParrot = function(parrotType) {

0 comments on commit 7b4f4b2

Please sign in to comment.