flattenize 1.1.11 → 1.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +14 -128
- package/lib/index.js +40 -35
- package/package.json +3 -2
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2014-
|
|
3
|
+
Copyright (c) 2014-26 Ionică Bizău <bizauionica@gmail.com> (https://ionicabizau.net)
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -1,52 +1,13 @@
|
|
|
1
1
|
<!-- Please do not edit this file. Edit the `blah` field in the `package.json` instead. If in doubt, open an issue. -->
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
3
|
# flattenize
|
|
21
4
|
|
|
22
|
-
[![Support me on Patreon][badge_patreon]][patreon] [![Buy me a book][badge_amazon]][amazon] [![PayPal][badge_paypal_donate]][paypal-donations] [](https://github.com/IonicaBizau/ama) [](https://www.npmjs.com/package/flattenize) [](https://www.npmjs.com/package/flattenize) [](https://www.codementor.io
|
|
5
|
+
[![Support me on Patreon][badge_patreon]][patreon] [![Buy me a book][badge_amazon]][amazon] [![PayPal][badge_paypal_donate]][paypal-donations] [](https://github.com/IonicaBizau/ama) [](https://www.npmjs.com/package/flattenize) [](https://www.npmjs.com/package/flattenize) [](https://www.codementor.io/@johnnyb?utm_source=github&utm_medium=button&utm_term=johnnyb&utm_campaign=github)
|
|
23
6
|
|
|
24
7
|
<a href="https://www.buymeacoffee.com/H96WwChMy" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/yellow_img.png" alt="Buy Me A Coffee"></a>
|
|
25
8
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
9
|
> An experiment for converting images in flat equivalents.
|
|
33
10
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
11
|
## :cloud: Installation
|
|
51
12
|
|
|
52
13
|
```sh
|
|
@@ -57,22 +18,8 @@ npm install --save flattenize
|
|
|
57
18
|
yarn add flattenize
|
|
58
19
|
```
|
|
59
20
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
21
|
## :clipboard: Example
|
|
73
22
|
|
|
74
|
-
|
|
75
|
-
|
|
76
23
|
```js
|
|
77
24
|
// Dependencies
|
|
78
25
|
var Flattenize = require ("../lib")
|
|
@@ -92,33 +39,8 @@ myImage._flatColors.push.apply(myImage._flatColors, [
|
|
|
92
39
|
myImage.convert("http://www.steegle.com/images/chrome.jpg");
|
|
93
40
|
```
|
|
94
41
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
## :question: Get Help
|
|
106
|
-
|
|
107
|
-
There are few ways to get help:
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
1. Please [post questions on Stack Overflow](https://stackoverflow.com/questions/ask). You can open issues with questions, as long you add a link to your Stack Overflow question.
|
|
112
|
-
2. For bug reports and feature requests, open issues. :bug:
|
|
113
|
-
3. For direct and quick help, you can [use Codementor](https://www.codementor.io/johnnyb). :rocket:
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
42
|
## :memo: Documentation
|
|
120
43
|
|
|
121
|
-
|
|
122
44
|
### `convertToPng()`
|
|
123
45
|
This function converts the image from options.imagePath to a png format.
|
|
124
46
|
|
|
@@ -126,77 +48,41 @@ This function converts the image from options.imagePath to a png format.
|
|
|
126
48
|
Converts a png image to flat
|
|
127
49
|
|
|
128
50
|
#### Params
|
|
129
|
-
|
|
130
51
|
- **String** `imagePath`: The path to the PNG image.
|
|
131
52
|
- **Function** `callback`: The callback function.
|
|
132
53
|
|
|
54
|
+
## :question: Get Help
|
|
133
55
|
|
|
56
|
+
There are a few ways to get help:
|
|
134
57
|
|
|
58
|
+
1. Please [post questions on Stack Overflow](https://stackoverflow.com/questions/ask). You can open issues with questions, as long as you add a link to your Stack Overflow question.
|
|
59
|
+
2. For bug reports and feature requests, open issues. :bug:
|
|
60
|
+
3. For direct and quick help, you can [use Codementor](https://www.codementor.io/johnnyb). :rocket:
|
|
135
61
|
|
|
62
|
+
## :yum: How to Contribute
|
|
136
63
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
## :yum: How to contribute
|
|
147
64
|
Have an idea? Found a bug? See [how to contribute][contributing].
|
|
148
65
|
|
|
66
|
+
## :sparkling_heart: Support My Projects
|
|
149
67
|
|
|
150
|
-
|
|
151
|
-
I open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously,
|
|
152
|
-
this takes time. You can integrate and use these projects in your applications *for free*! You can even change the source code and redistribute (even resell it).
|
|
153
|
-
|
|
154
|
-
However, if you get some profit from this or just want to encourage me to continue creating stuff, there are few ways you can do it:
|
|
68
|
+
I open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously, this takes time. You can integrate and use these projects in your applications *for free*! You can even change the source code and redistribute it (even resell it).
|
|
155
69
|
|
|
70
|
+
However, if you get some profit from this or just want to encourage me to continue creating stuff, there are a few ways you can do it:
|
|
156
71
|
|
|
157
72
|
- Starring and sharing the projects you like :rocket:
|
|
158
|
-
- [![Buy me a book][badge_amazon]][amazon]—I love books! I will remember you
|
|
73
|
+
- [![Buy me a book][badge_amazon]][amazon]—I love books! I will remember you for years if you buy me one. :grin: :book:
|
|
159
74
|
- [![PayPal][badge_paypal]][paypal-donations]—You can make one-time donations via PayPal. I'll probably buy a ~~coffee~~ tea. :tea:
|
|
160
75
|
- [![Support me on Patreon][badge_patreon]][patreon]—Set up a recurring monthly donation and you will get interesting news about what I'm doing (things that I don't share with everyone).
|
|
161
|
-
- **Bitcoin**—You can send me bitcoins at this address (or scanning the code below): `1P9BRsmazNQcuyTxEqveUsnf5CERdq35V6`
|
|
162
|
-
|
|
163
|
-

|
|
76
|
+
- **Bitcoin**—You can send me bitcoins at this address (or by scanning the code below): `1P9BRsmazNQcuyTxEqveUsnf5CERdq35V6`
|
|
164
77
|
|
|
78
|
+

|
|
165
79
|
|
|
166
80
|
Thanks! :heart:
|
|
167
81
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
82
|
## :scroll: License
|
|
192
83
|
|
|
193
84
|
[MIT][license] © [Ionică Bizău][website]
|
|
194
85
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
86
|
[license]: /LICENSE
|
|
201
87
|
[website]: https://ionicabizau.net
|
|
202
88
|
[contributing]: /CONTRIBUTING.md
|
|
@@ -206,5 +92,5 @@ Thanks! :heart:
|
|
|
206
92
|
[badge_paypal]: https://ionicabizau.github.io/badges/paypal.svg
|
|
207
93
|
[badge_paypal_donate]: https://ionicabizau.github.io/badges/paypal_donate.svg
|
|
208
94
|
[patreon]: https://www.patreon.com/ionicabizau
|
|
209
|
-
[amazon]:
|
|
95
|
+
[amazon]: https://amzn.eu/hRo9sIZ
|
|
210
96
|
[paypal-donations]: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RVXDDLKKLQRJW
|
package/lib/index.js
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
// dependencies
|
|
4
|
-
var fs = require('fs')
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
var fs = require('fs')
|
|
3
|
+
, PNG = require('pngjs').PNG
|
|
4
|
+
, ImageMagick = require("imagemagick")
|
|
5
|
+
, FlatColors = require("flatcolors")
|
|
6
|
+
, Request = require('request')
|
|
7
|
+
, typpy = require("typpy")
|
|
8
|
+
;
|
|
10
9
|
|
|
11
10
|
/**
|
|
12
11
|
* This function converts the image from options.imagePath to a png format.
|
|
13
12
|
*
|
|
14
13
|
*/
|
|
15
|
-
function convertToPng(options, callback) {
|
|
14
|
+
function convertToPng (options, callback) {
|
|
16
15
|
|
|
17
16
|
// get the instance
|
|
18
17
|
var self = this;
|
|
@@ -21,28 +20,27 @@ function convertToPng(options, callback) {
|
|
|
21
20
|
var tmpPath = "image-" + Math.random().toString(36) + ".png";
|
|
22
21
|
|
|
23
22
|
// get the image size
|
|
24
|
-
ImageMagick.identify(options.imagePath, function (err, imageData)
|
|
23
|
+
ImageMagick.identify(options.imagePath, function (err, imageData){
|
|
25
24
|
|
|
26
25
|
// handle error
|
|
27
|
-
if (err) {
|
|
28
|
-
return callback(err);
|
|
29
|
-
}
|
|
26
|
+
if (err) { return callback (err); }
|
|
30
27
|
|
|
31
28
|
// convert the image
|
|
32
|
-
ImageMagick.convert([
|
|
29
|
+
ImageMagick.convert([
|
|
30
|
+
options.imagePath
|
|
31
|
+
, tmpPath
|
|
32
|
+
], function(err, stdout){
|
|
33
33
|
|
|
34
34
|
// handle error
|
|
35
|
-
if (err) {
|
|
36
|
-
return callback(err);
|
|
37
|
-
}
|
|
35
|
+
if (err) { return callback (err); }
|
|
38
36
|
|
|
39
37
|
// callback
|
|
40
|
-
callback(null, tmpPath);
|
|
38
|
+
callback (null, tmpPath);
|
|
41
39
|
});
|
|
42
40
|
});
|
|
43
41
|
}
|
|
44
42
|
|
|
45
|
-
var Flattenize = function
|
|
43
|
+
var Flattenize = function (options) {
|
|
46
44
|
|
|
47
45
|
// build the instance
|
|
48
46
|
var self = this;
|
|
@@ -58,13 +56,14 @@ var Flattenize = function Flattenize(options) {
|
|
|
58
56
|
*/
|
|
59
57
|
self.convert = function (imagePath, callback) {
|
|
60
58
|
|
|
59
|
+
|
|
61
60
|
// force image path to be a string
|
|
62
|
-
imagePath = String(imagePath);
|
|
61
|
+
imagePath = String (imagePath);
|
|
63
62
|
|
|
64
63
|
// force callback to be a function
|
|
65
64
|
callback = callback || function () {};
|
|
66
65
|
if (typeof callback !== "function") {
|
|
67
|
-
throw new Error("Callback must be a function");
|
|
66
|
+
throw new Error ("Callback must be a function");
|
|
68
67
|
}
|
|
69
68
|
|
|
70
69
|
// the string begins with https or http
|
|
@@ -74,24 +73,24 @@ var Flattenize = function Flattenize(options) {
|
|
|
74
73
|
var tmpPath = "image-" + Math.random().toString(36);
|
|
75
74
|
|
|
76
75
|
// download the image
|
|
77
|
-
Request(imagePath)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
Request(imagePath)
|
|
77
|
+
.pipe(fs.createWriteStream(tmpPath))
|
|
78
|
+
.on('close', function () {
|
|
79
|
+
self.convert (tmpPath, function (err, data) {
|
|
80
|
+
callback (err, data);
|
|
81
|
+
fs.unlink (tmpPath);
|
|
82
|
+
});
|
|
81
83
|
});
|
|
82
|
-
});
|
|
83
84
|
return;
|
|
84
85
|
}
|
|
85
86
|
|
|
86
87
|
// convert to png
|
|
87
|
-
convertToPng.call(self, {
|
|
88
|
+
convertToPng.call (self, {
|
|
88
89
|
imagePath: imagePath
|
|
89
90
|
}, function (err, tmpPath) {
|
|
90
91
|
|
|
91
92
|
// handle error
|
|
92
|
-
if (err) {
|
|
93
|
-
return callback(err);
|
|
94
|
-
}
|
|
93
|
+
if (err) { return callback (err); }
|
|
95
94
|
|
|
96
95
|
// read the image
|
|
97
96
|
var stream = fs.createReadStream(tmpPath).pipe(new PNG({ filterType: 4 }));
|
|
@@ -101,9 +100,14 @@ var Flattenize = function Flattenize(options) {
|
|
|
101
100
|
|
|
102
101
|
for (var y = 0; y < this.height; ++y) {
|
|
103
102
|
for (var x = 0; x < this.width; ++x) {
|
|
104
|
-
var idx = this.width * y + x << 2
|
|
105
|
-
|
|
106
|
-
|
|
103
|
+
var idx = (this.width * y + x) << 2
|
|
104
|
+
, rgb = [
|
|
105
|
+
this.data[idx]
|
|
106
|
+
, this.data[idx + 1]
|
|
107
|
+
, this.data[idx + 2]
|
|
108
|
+
]
|
|
109
|
+
, newRgb = FlatColors(rgb)
|
|
110
|
+
;
|
|
107
111
|
|
|
108
112
|
this.data[idx] = newRgb[0];
|
|
109
113
|
this.data[idx + 1] = newRgb[1];
|
|
@@ -114,10 +118,11 @@ var Flattenize = function Flattenize(options) {
|
|
|
114
118
|
this.pack().pipe(fs.createWriteStream('out.png'));
|
|
115
119
|
});
|
|
116
120
|
});
|
|
117
|
-
}
|
|
121
|
+
}
|
|
118
122
|
|
|
119
123
|
self._flatColors = FlatColors._colors;
|
|
120
124
|
return self;
|
|
121
125
|
};
|
|
122
126
|
|
|
123
|
-
|
|
127
|
+
|
|
128
|
+
module.exports = Flattenize;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flattenize",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.13",
|
|
4
4
|
"description": "An experiment for converting images in flat equivalents.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"dependencies": {
|
|
@@ -42,8 +42,9 @@
|
|
|
42
42
|
"menu/",
|
|
43
43
|
"cli.js",
|
|
44
44
|
"index.js",
|
|
45
|
+
"index.d.ts",
|
|
45
46
|
"bloggify.js",
|
|
46
47
|
"bloggify.json",
|
|
47
48
|
"bloggify/"
|
|
48
49
|
]
|
|
49
|
-
}
|
|
50
|
+
}
|