ansi-gif
Advanced tools
Comparing version 0.0.4 to 0.1.0
77
gif.js
var asynk = require('async'); | ||
var Color = require('ascii-art-ansi/color'); | ||
var Image = require('ascii-art-image'); | ||
var request = require('request'); | ||
@@ -33,3 +34,7 @@ //Color.is256 = true; //also supports .isTrueColor if your terminal does | ||
this.options = options; | ||
this.stream = fs.createReadStream(options.file); | ||
if(options.file.indexOf('http') === 0){ | ||
this.stream = request.get(options.file) | ||
}else{ | ||
this.stream = fs.createReadStream(options.file); | ||
} | ||
} | ||
@@ -44,9 +49,71 @@ | ||
var count = 0; | ||
asynk.eachOfLimit(this.frames, 2, function(frame, index, done){ | ||
var last; | ||
var height; | ||
var width; | ||
asynk.eachOfLimit(this.frames, 1, function(frame, index, done){ | ||
if(!height) height = frame.height; | ||
if(!width) width = frame.width; | ||
var last | ||
var image = new Image({ | ||
width : ob.options.width || 80, | ||
imagePixelFrame : frame, | ||
alphabet : ob.options.alphabet || 'variant4' | ||
alphabet : ob.options.alphabet || 'variant4', | ||
loader : function(image, setAspectRatio, Canvas, Image){ | ||
setAspectRatio(height/width); | ||
if(frame.x || frame.y){ | ||
var canvas = new Canvas(height, width); | ||
var context = canvas.getContext('2d'); | ||
if(last){ | ||
context.putImageData( | ||
last, 0, 0 | ||
); | ||
} | ||
var imageData = context.getImageData( | ||
(frame.x || 0), | ||
(frame.y || 0), | ||
(frame.width || undefined), | ||
(frame.height || undefined) | ||
); | ||
var data = imageData.data; | ||
var len = frame.width * frame.height; | ||
var offset; | ||
var pixset; | ||
for (var i=0; i < len;i += 4) { | ||
offset = i * 4; | ||
pixset = i * 3; | ||
data[offset] = frame.pixels.readUInt8(pixset); | ||
data[offset+1] = frame.pixels.readUInt8(pixset+1); | ||
data[offset+2] = frame.pixels.readUInt8(pixset+2); | ||
data[offset+3] = 255; | ||
} | ||
context.putImageData( | ||
imageData, | ||
(frame.x || 0), | ||
(frame.y || 0) | ||
); | ||
last = imageData; | ||
return {context, canvas}; | ||
}else{ | ||
var canvas = new Canvas(frame.width, frame.height); | ||
var context = canvas.getContext('2d'); | ||
var dataContext = context.getImageData(0,0,frame.width, frame.height); | ||
var imageData = dataContext.data; | ||
var len = frame.width * frame.height; | ||
var offset; | ||
var pixset; | ||
for (var i=0; i < len;i += 4) { | ||
offset = i * 4; | ||
pixset = i * 3; | ||
imageData[offset] = frame.pixels.readUInt8(pixset); | ||
imageData[offset+1] = frame.pixels.readUInt8(pixset+1); | ||
imageData[offset+2] = frame.pixels.readUInt8(pixset+2); | ||
imageData[offset+3] = 255; | ||
} | ||
last = dataContext; | ||
context.putImageData(dataContext, 0, 0); | ||
return {context, canvas}; | ||
} | ||
} | ||
}); | ||
image.write(function(err, image){ | ||
image.write(function(err, image, context2d){ | ||
last = context2d; | ||
if(err) return console.log(err); | ||
@@ -53,0 +120,0 @@ renderedFrames[index] = image; |
{ | ||
"name": "ansi-gif", | ||
"version": "0.0.4", | ||
"version": "0.1.0", | ||
"homepage": "https://github.com/khrome/ansi-gif", | ||
"main": "gif.js", | ||
"description": "View animated GIFs in your terminal", | ||
"description": "View animated, color GIFs in your terminal", | ||
"keywords": [ | ||
@@ -42,2 +42,3 @@ "ascii", | ||
"gif-stream": "^1.1.0", | ||
"request": "^2.88.0", | ||
"yargs": "^14.2.0" | ||
@@ -47,10 +48,10 @@ }, | ||
"nyan-cat": "./bin/ansi-gif -b 8 -d ratioDistance -a ultra-wide ./node_modules/ascii-art-docs/GIFs/nyan.gif", | ||
"mj-popcorn":"./bin/ansi-gif -b 4 -a hatching ./node_modules/ascii-art-docs/GIFs/mj-popcorn.gif", | ||
"beetlejuice-caseworker":"./bin/ansi-gif -b 8 -d rankedChannel -a hatching ./node_modules/ascii-art-docs/GIFs/beetlejuice-caseworker.gif", | ||
"afro-ninja":"./bin/ansi-gif -b 8 -d rankedChannel -a ultra-wide ./node_modules/ascii-art-docs/GIFs/afro-ninja.gif", | ||
"peanuts":"./bin/ansi-gif -b 8 -d classicByValue -a ultra-wide ./node_modules/ascii-art-docs/GIFs/pean.gif", | ||
"geometry":"./bin/ansi-gif -b 8 -d classicByValue -a ultra-wide ./node_modules/ascii-art-docs/GIFs/geo.gif", | ||
"maxell":"./bin/ansi-gif -b 8 -d classicByValue -a ultra-wide ./node_modules/ascii-art-docs/GIFs/rh.gif", | ||
"moon":"./bin/ansi-gif -b 8 -d classicByValue -a ultra-wide ./node_modules/ascii-art-docs/GIFs/moon.gif", | ||
"mr-sparkle":"./bin/ansi-gif -b 8 -d rankedChannel -a variant3 ./node_modules/ascii-art-docs/GIFs/sparkle.gif" | ||
"mj-popcorn": "./bin/ansi-gif -b 4 -a hatching ./node_modules/ascii-art-docs/GIFs/mj-popcorn.gif", | ||
"beetlejuice-caseworker": "./bin/ansi-gif -b 8 -d rankedChannel -a hatching ./node_modules/ascii-art-docs/GIFs/beetlejuice-caseworker.gif", | ||
"afro-ninja": "./bin/ansi-gif -b 8 -d rankedChannel -a ultra-wide ./node_modules/ascii-art-docs/GIFs/afro-ninja.gif", | ||
"peanuts": "./bin/ansi-gif -b 8 -d classicByValue -a ultra-wide ./node_modules/ascii-art-docs/GIFs/pean.gif", | ||
"geometry": "./bin/ansi-gif -b 8 -d classicByValue -a ultra-wide ./node_modules/ascii-art-docs/GIFs/geo.gif", | ||
"maxell": "./bin/ansi-gif -b 8 -d classicByValue -a ultra-wide ./node_modules/ascii-art-docs/GIFs/rh.gif", | ||
"moon": "./bin/ansi-gif -b 8 -d classicByValue -a ultra-wide ./node_modules/ascii-art-docs/GIFs/moon.gif", | ||
"mr-sparkle": "./bin/ansi-gif -b 8 -d rankedChannel -a variant3 ./node_modules/ascii-art-docs/GIFs/sparkle.gif" | ||
}, | ||
@@ -57,0 +58,0 @@ "devDependencies": { |
@@ -7,8 +7,12 @@ ansi-gif | ||
View gifs in your terminal | ||
View gifs in your terminal. 100% JS, no ffmpeg. | ||
![nyan-cat](Samples/nyan.gif) | ||
Currently only supports gifs that use full frame rendering. subframe support coming soon™ | ||
Supports full frame and subframe rendering™ | ||
Given that this is a new library and there are many configurations of GIFs out there, we may not catch every edge case. Please save any example files yuo have with issues (and file them)! | ||
As simple as: `ansi-gif <file or url>` | ||
Installation | ||
@@ -56,4 +60,2 @@ ------------ | ||
`npm run moon` | ||
`npm run mr-sparkle` | ||
@@ -65,2 +67,4 @@ | ||
![nyan-cat](Samples/nyan.gif) | ||
`npm run beetlejuice-caseworker` | ||
@@ -72,2 +76,6 @@ | ||
`npm run moon` | ||
![nyan-cat](Samples/moon.gif) | ||
`npm run geometry` | ||
@@ -74,0 +82,0 @@ |
2289531
9
144
82
9
+ Addedrequest@^2.88.0
+ Addedajv@6.12.6(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.0(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedpsl@1.9.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedverror@1.10.0(transitive)