Skip to content

Instantly share code, notes, and snippets.

@abinavseelan
abinavseelan / server.js
Last active August 24, 2017 08:59
Medium - Image Manipulation with NodeJs - Bootstrapping the application
const express = require('express');
const app = express();
const port = 1337;
app.get('/ping', (request, response) => {
response.send('Pong!');
});
app.listen(port, () => {
console.log(`Server running on port ${port}`);
@abinavseelan
abinavseelan / crop.js
Created August 24, 2017 09:09
Medium - Image Manipulation using NodeJS - Cropping
const gm = require('gm');
const width = 300;
const height = 400;
gm('/path/to/image/file')
.crop(width, height)
.write('/path/to/output', (err) => {
if (err) {
console.log(err);
}
@abinavseelan
abinavseelan / server.js
Created August 24, 2017 09:22
Medium - Image Manipulation using NodeJS - Cropping endpoint
const express = require('express');
const app = express();
const gm = require('gm'); // Require the GraphicsMagick wrapper for node
const fs = require('fs'); // To clean up after the we generate the output image file
const port = 1337;
app.get('/ping', (request, response) => {
response.send('Pong!');
});
@abinavseelan
abinavseelan / crop.js
Created August 24, 2017 09:26
Medium - Image Manipulation using NodeJS - Cropping and center Endpoint
const express = require('express');
const app = express();
const gm = require('gm');
const fs = require('fs');
const port = 1337;
app.get('/ping', (request, response) => {
response.send('Pong!');
});
@abinavseelan
abinavseelan / resize.js
Created August 24, 2017 13:30
Medium - Image Manipulation using NodeJS - Resize
const gm = require('gm');
const width = 200;
const height = 50;
gm('/path/to/image/file')
.resize(width, null) // This will resize the width while maintaining the aspect ratio
.write('/path/to/output', (err) => {
if (err) {
console.log(err);
}
@abinavseelan
abinavseelan / resize.js
Created August 24, 2017 13:35
Medium - Image Manipulation using NodeJS - Resize endpoint
const express = require('express');
const app = express();
const gm = require('gm');
const fs = require('fs');
const port = 1337;
app.get('/ping', (request, response) => {
response.send('Pong!');
});
@abinavseelan
abinavseelan / queue.js
Last active August 25, 2017 18:10
Medium - DS in Javascript - Building the constructor
function Queue () {
this.values = [];
this.count = 0;
}
@abinavseelan
abinavseelan / queue.js
Last active August 26, 2017 05:05
Medium - DS in Javascript - push Method
function Queue() {
this.values = [];
this.count = 0;
}
Queue.prototype.enqueue = (newValue) => {
this.values[this.count] = newValue; // Insert the new value in the end
this.count++; // Update the count to reflect the addition
}
@abinavseelan
abinavseelan / queue.js
Last active August 26, 2017 05:05
Medium - DS in Javascript - Queue - pop()
function Queue() {
this.values = [];
this.count = 0;
}
Queue.prototype.enqueue = (newValue) => {
this.values[this.count] = newValue;
this.count++;
}
@abinavseelan
abinavseelan / queue.js
Last active August 26, 2017 05:04
Medium - DS in Javascript - Queue - Length Method
function Queue() {
this.values = [];
this.count = 0;
}
Queue.prototype.enqueue = (newValue) => {
this.values[this.count] = newValue;
this.count++;
}