Created
February 26, 2016 10:43
-
-
Save a13x/81d6a88a3bf97599b780 to your computer and use it in GitHub Desktop.
Serving image via output stream with ningle, running on woo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ql:quickload :clack :silent t) | |
(ql:quickload :vecto :silent t) | |
(ql:quickload :ningle :silent t) | |
(ql:quickload :babel :silent t) | |
(ql:quickload :babel-streams :silent t) | |
(in-package :cl-user) | |
(defpackage imger | |
(:use :cl :ningle :babel :babel-streams :vecto) | |
(:import-from :lack.response | |
:response-status | |
:response-headers) | |
(:import-from :ningle | |
:*response*) | |
(:import-from :babel-streams | |
:with-output-to-sequence) | |
(:import-from :vecto | |
:with-canvas | |
:set-rgb-fill | |
:clear-canvas | |
:save-png-stream) | |
(:export :start) | |
) | |
(in-package :imger) | |
(defvar *app* (make-instance '<app>)) | |
(defvar *h* nil) | |
(defmacro n-param (param params) | |
`(parse-integer (cdr (assoc ,param ,params)))) | |
(defun serve-image (params) | |
(let ((w (n-param :w params)) | |
(h (n-param :h params))) | |
(progn | |
(setf (response-status *response*) 200) | |
(setf (getf (response-headers *response*) :content-type) "image/png") | |
(with-output-to-sequence (s) | |
(with-canvas (:width w :height h) | |
(set-rgb-fill 0.2 0.2 0.9) | |
(clear-canvas) | |
(save-png-stream s)) | |
:element-type '(unsigned-byte 8))))) | |
(setf (route *app* "/i/:w/:h") #'serve-image) | |
(defun start () | |
(setf *h* (clack:clackup *app* :server :woo))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment