Created
December 29, 2015 07:56
-
-
Save alecrem/d859084cfc0e98454204 to your computer and use it in GitHub Desktop.
[Studio Kura]各教室のページの背景をflickrダウンロードして、軽くする
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fs = require 'fs' | |
request = require 'request' | |
gm = require 'gm' | |
.subClass {imageMagick: true} | |
filenames = ['bg-title.jpg', 'bg-otona.jpg', 'bg-kodomo.jpg', 'bg-denshi.jpg', 'bg-timetable.jpg', 'bg-map.jpg'] | |
filenamesg = ['bgg-title.jpg', 'bgg-otona.jpg', 'bgg-kodomo.jpg', 'bgg-denshi.jpg', 'bgg-timetable.jpg', 'bgg-map.jpg'] | |
filename_index = -1 | |
lineReader = require 'readline' | |
.createInterface { | |
input: fs.createReadStream 'bgimgdl-list.txt' | |
} | |
download = (uri, filename, callback) -> | |
if uri | |
request.head uri, (err, res, body) -> | |
console.log 'content-length:', res.headers['content-length'] | |
console.log 'content-type:', res.headers['content-type'] | |
request uri | |
.pipe fs.createWriteStream filename | |
.on 'close', callback | |
lineReader.on 'line', (line) -> | |
filename_index = filename_index + 1 | |
if !fs.existsSync filenames[filename_index] | |
console.log 'downloading: ' + filenames[filename_index] | |
download line, filenames[filename_index], -> | |
console.log 'done' | |
if !fs.existsSync filenamesg[filename_index] && fs.existsSync filenames[filename_index] | |
gm filenames[filename_index] | |
.quality 40 | |
.write filenamesg[filename_index], (err)-> | |
if err | |
console.log 'error converting quality: ' + err | |
else | |
console.log 'quality converted correctly' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment