Skip to content

Commit

Permalink
画像ファイルのヘッダがGIF89aの場合はgif画像としてフロントに返す #189 (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiro4989 committed Nov 25, 2020
1 parent d121b81 commit 11de0e4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 6 additions & 1 deletion websh_front/src/index.nim
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type
ImageObj = object
image: cstring
filesize: cint
format: cstring
MediaObj = object
name, data: cstring

Expand Down Expand Up @@ -248,7 +249,11 @@ proc createDom(): VNode =
for img in outputImages:
tdiv:
# imgでbase64を表示するときに必要なメタ情報を追加
img(src = "data:image/png;base64," & img.image)
case $img.format
of "gif":
img(src = "data:image/gif;base64," & img.image)
else:
img(src = "data:image/png;base64," & img.image)
tdiv:
text &"{img.filesize} byte"

Expand Down
9 changes: 8 additions & 1 deletion websh_server/src/websh_server.nim
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type
ImageObj* = object
image*: string
filesize*: int
format*: string

const
scriptName = "exec.sh"
Expand All @@ -29,7 +30,13 @@ proc getImages(dir: string): seq[ImageObj] =
if not path.existsFile:
continue
let content = readFile(path)
let img = ImageObj(image: base64.encode(content), filesize: content.len)
var format = "png"
if 6 < content.len:
let f = content[0..<6]
case f
of "GIF89a": format = "gif"
else: discard
let img = ImageObj(image: base64.encode(content), filesize: content.len, format: format)
result.add(img)

proc createMediaFiles(dir: string, medias: seq[string]) =
Expand Down

0 comments on commit 11de0e4

Please sign in to comment.