Skip to content

Instantly share code, notes, and snippets.

@saihoooooooo
Last active December 18, 2015 13:19
Show Gist options
  • Save saihoooooooo/82adf1fc04d37bce50e8 to your computer and use it in GitHub Desktop.
Save saihoooooooo/82adf1fc04d37bce50e8 to your computer and use it in GitHub Desktop.
generator test
Promise = require 'bluebird'
im = Promise.promisifyAll require 'imagemagick'
input = './img/bb.png'
resize = './img/resize.png'
crop = './img/crop.png'
exec = ->
ext = yield im.identifyAsync ['-format', '%m', input]
console.log ext.toLowerCase()
yield im.convertAsync [input, '-resize', '200x200!', resize]
yield im.convertAsync [resize, '-crop', '100x100', crop]
Promise.coroutine(exec)().catch (err) ->
console.log err
const Promise = require('bluebird');
const im = Promise.promisifyAll(require('imagemagick'));
const input = './img/bb.png';
const resize = './img/resize.png';
const crop = './img/crop.png';
const exec = function*() {
const ext = yield im.identifyAsync(['-format', '%m', input]);
console.log(ext.toLowerCase());
yield im.convertAsync([input, '-resize', '200x200!', resize]);
yield im.convertAsync([resize, '-crop', '100x100', crop]);
}
Promise.coroutine(exec)().catch((err) => {
console.log(err);
});
requirement
node v4.0.0 以上 or --harmony flag or --harmony-generators
npm install glob
Promise = require 'bluebird'
im = Promise.promisifyAll require 'imagemagick'
client = require 'cheerio-httpcli'
globAsync = Promise.promisify require 'glob'
path = require 'path'
input = './img/bb.png'
resize = './img/resize.png'
crop = './img/crop.png'
teamName = 'xxx'
email = 'xxx@gmail.com'
password = 'xxx'
exec = ->
ext = yield im.identifyAsync ['-format', '%m', input]
console.log ext.toLowerCase()
yield im.convertAsync [input, '-resize', '200x200!', resize]
yield im.convertAsync [resize, '-crop', '100x100', crop]
emojiPageUrl = "https://#{teamName}.slack.com/admin/emoji"
page = yield client.fetch emojiPageUrl
loginInput =
email: email
password: password
page = yield page.$('#signin_form').submit(loginInput)
if page.$.documentInfo().url != emojiPageUrl
throw new Error 'hogegeeeee'
files = yield globAsync('./img/crop*')
for file in files
emojiInput =
name: path.basename(file, 'png')
img: file
page = yield page.$('#addemoji').submit(loginInput)
console.log page.$('.alert_error').text()
Promise.coroutine(exec)().catch (err) ->
console.log err
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment