Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
D
Docker Choco
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Docker Choco
Commits
4f9c980a
Commit
4f9c980a
authored
Oct 03, 2018
by
Stefan Scherer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use jimp to print hostname to photo
parent
c0d53b6b
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
593 additions
and
14 deletions
+593
-14
appetizer/.gitignore
appetizer/.gitignore
+1
-0
appetizer/Dockerfile
appetizer/Dockerfile
+1
-0
appetizer/app.js
appetizer/app.js
+23
-13
appetizer/package-lock.json
appetizer/package-lock.json
+564
-0
appetizer/package.json
appetizer/package.json
+4
-1
No files found.
appetizer/.gitignore
View file @
4f9c980a
img/*.jpg
img/*.jpg
node_modules/
appetizer/Dockerfile
View file @
4f9c980a
...
@@ -2,6 +2,7 @@ FROM chocolateyfest/node
...
@@ -2,6 +2,7 @@ FROM chocolateyfest/node
WORKDIR
/app
WORKDIR
/app
COPY
img img
COPY
img img
COPY
package.json package.json
COPY
package.json package.json
RUN
npm
install
--production
COPY
app.js app.js
COPY
app.js app.js
FROM
chocolateyfest/node:pure
FROM
chocolateyfest/node:pure
WORKDIR
/app
WORKDIR
/app
...
...
appetizer/app.js
View file @
4f9c980a
...
@@ -2,7 +2,9 @@
...
@@ -2,7 +2,9 @@
const
fs
=
require
(
'
fs
'
);
const
fs
=
require
(
'
fs
'
);
const
files
=
fs
.
readdirSync
(
'
img
'
);
const
files
=
fs
.
readdirSync
(
'
img
'
);
const
Jimp
=
require
(
'
jimp
'
);
const
http
=
require
(
'
http
'
);
const
http
=
require
(
'
http
'
);
const
os
=
require
(
'
os
'
);
const
port
=
8080
;
const
port
=
8080
;
for
(
let
i
=
files
.
length
-
1
;
i
>=
0
;
i
--
)
{
for
(
let
i
=
files
.
length
-
1
;
i
>=
0
;
i
--
)
{
...
@@ -13,17 +15,25 @@ const pos = Math.floor(Math.random() * files.length);
...
@@ -13,17 +15,25 @@ const pos = Math.floor(Math.random() * files.length);
const
file
=
files
[
pos
];
const
file
=
files
[
pos
];
console
.
log
(
`Got
${
files
.
length
}
img files, choosing position
${
pos
}
.`
);
console
.
log
(
`Got
${
files
.
length
}
img files, choosing position
${
pos
}
.`
);
http
.
createServer
((
req
,
res
)
=>
{
const
path
=
`img/
${
file
}
`
;
const
path
=
`img/
${
file
}
`
;
fs
.
readFile
(
path
,
(
err
,
data
)
=>
{
if
(
err
)
{
res
.
writeHead
(
404
,
{
'
Content-Type
'
:
'
text/plain
'
});
res
.
end
(
`Error handling:
${
path
}
\n`
);
}
else
{
res
.
writeHead
(
200
,
{
'
Content-Type
'
:
'
image/jpeg
'
,
'
Connection
'
:
'
close
'
});
res
.
end
(
data
,
'
binary
'
);
}
})
}).
listen
(
port
);
console
.
log
(
`Listening on port
${
port
}
serving file
${
file
}
.`
);
Jimp
.
read
(
path
).
then
(
image
=>
{
console
.
log
(
'
Got image
'
);
Jimp
.
loadFont
(
Jimp
.
FONT_SANS_32_BLACK
).
then
(
black
=>
{
Jimp
.
loadFont
(
Jimp
.
FONT_SANS_32_WHITE
).
then
(
white
=>
{
console
.
log
(
'
Got font
'
);
image
.
scaleToFit
(
800
,
600
)
.
print
(
black
,
10
,
10
,
os
.
hostname
())
.
print
(
white
,
8
,
8
,
os
.
hostname
())
.
quality
(
98
)
// set JPEG quality
.
getBuffer
(
Jimp
.
MIME_JPEG
,
(
err
,
data
)
=>
{
console
.
log
(
`Listening on port
${
port
}
serving file
${
file
}
.`
);
http
.
createServer
((
req
,
res
)
=>
{
res
.
writeHead
(
200
,
{
'
Content-Type
'
:
Jimp
.
MIME_JPEG
,
'
Connection
'
:
'
close
'
});
res
.
end
(
data
,
'
binary
'
);
}).
listen
(
port
);
});
});
});
});
appetizer/package-lock.json
0 → 100644
View file @
4f9c980a
This diff is collapsed.
Click to expand it.
appetizer/package.json
View file @
4f9c980a
...
@@ -7,5 +7,8 @@
...
@@ -7,5 +7,8 @@
"test"
:
"echo
\"
Error: no test specified
\"
&& exit 1"
"test"
:
"echo
\"
Error: no test specified
\"
&& exit 1"
},
},
"author"
:
"Stefan Scherer"
,
"author"
:
"Stefan Scherer"
,
"license"
:
"Apache-2.0"
"license"
:
"Apache-2.0"
,
"dependencies"
:
{
"jimp"
:
"0.5.3"
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment