1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | var Image = function (faker) {
|
10 |
|
11 | var self = this;
|
12 | var Lorempixel = require('./image_providers/lorempixel');
|
13 | var Unsplash = require('./image_providers/unsplash');
|
14 | var LoremPicsum = require('./image_providers/lorempicsum');
|
15 |
|
16 | |
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | self.image = function (width, height, randomize) {
|
25 | var categories = ["abstract", "animals", "business", "cats", "city", "food", "nightlife", "fashion", "people", "nature", "sports", "technics", "transport"];
|
26 | return self[faker.random.arrayElement(categories)](width, height, randomize);
|
27 | };
|
28 | |
29 |
|
30 |
|
31 |
|
32 |
|
33 | self.avatar = function () {
|
34 | return faker.internet.avatar();
|
35 | };
|
36 | |
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 | self.imageUrl = function (width, height, category, randomize, https) {
|
46 | var width = width || 640;
|
47 | var height = height || 480;
|
48 | var protocol = 'http://';
|
49 | if (typeof https !== 'undefined' && https === true) {
|
50 | protocol = 'https://';
|
51 | }
|
52 | var url = protocol + 'placeimg.com/' + width + '/' + height;
|
53 | if (typeof category !== 'undefined') {
|
54 | url += '/' + category;
|
55 | }
|
56 |
|
57 | if (randomize) {
|
58 | url += '?' + faker.datatype.number()
|
59 | }
|
60 |
|
61 | return url;
|
62 | };
|
63 | |
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 | self.abstract = function (width, height, randomize) {
|
72 | return faker.image.imageUrl(width, height, 'abstract', randomize);
|
73 | };
|
74 | |
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 | self.animals = function (width, height, randomize) {
|
83 | return faker.image.imageUrl(width, height, 'animals', randomize);
|
84 | };
|
85 | |
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 | self.business = function (width, height, randomize) {
|
94 | return faker.image.imageUrl(width, height, 'business', randomize);
|
95 | };
|
96 | |
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 | self.cats = function (width, height, randomize) {
|
105 | return faker.image.imageUrl(width, height, 'cats', randomize);
|
106 | };
|
107 | |
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 | self.city = function (width, height, randomize) {
|
116 | return faker.image.imageUrl(width, height, 'city', randomize);
|
117 | };
|
118 | |
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 | self.food = function (width, height, randomize) {
|
127 | return faker.image.imageUrl(width, height, 'food', randomize);
|
128 | };
|
129 | |
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 | self.nightlife = function (width, height, randomize) {
|
138 | return faker.image.imageUrl(width, height, 'nightlife', randomize);
|
139 | };
|
140 | |
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 | self.fashion = function (width, height, randomize) {
|
149 | return faker.image.imageUrl(width, height, 'fashion', randomize);
|
150 | };
|
151 | |
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 | self.people = function (width, height, randomize) {
|
160 | return faker.image.imageUrl(width, height, 'people', randomize);
|
161 | };
|
162 | |
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 | self.nature = function (width, height, randomize) {
|
171 | return faker.image.imageUrl(width, height, 'nature', randomize);
|
172 | };
|
173 | |
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 |
|
180 |
|
181 | self.sports = function (width, height, randomize) {
|
182 | return faker.image.imageUrl(width, height, 'sports', randomize);
|
183 | };
|
184 | |
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 | self.technics = function (width, height, randomize) {
|
193 | return faker.image.imageUrl(width, height, 'technics', randomize);
|
194 | };
|
195 | |
196 |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 | self.transport = function (width, height, randomize) {
|
204 | return faker.image.imageUrl(width, height, 'transport', randomize);
|
205 | };
|
206 | |
207 |
|
208 |
|
209 |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 | self.dataUri = function (width, height, color) {
|
215 | color = color || 'grey';
|
216 | var svgString = '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" baseProfile="full" width="' + width + '" height="' + height + '"><rect width="100%" height="100%" fill="' + color + '"/><text x="' + width / 2 + '" y="' + height / 2 + '" font-size="20" alignment-baseline="middle" text-anchor="middle" fill="white">' + width + 'x' + height + '</text></svg>';
|
217 | var rawPrefix = 'data:image/svg+xml;charset=UTF-8,';
|
218 | return rawPrefix + encodeURIComponent(svgString);
|
219 | };
|
220 |
|
221 | self.lorempixel = new Lorempixel(faker);
|
222 | self.unsplash = new Unsplash(faker);
|
223 | self.lorempicsum = new LoremPicsum(faker);
|
224 |
|
225 |
|
226 |
|
227 | }
|
228 |
|
229 |
|
230 | module["exports"] = Image;
|