Works again.
[uxul-world.git] / imagemagick.lisp
1 ;; Copyright 2010-2011 Christoph Senjak\r
2 \r
3 (in-package :uxul-world)\r
4 \r
5 ;; "Binding" for the "convert"-Program\r
6 \r
7 (defparameter *convert* #P"C:\\Program Files (x86)\\ImageMagick-6.6.2-Q16\\convert.exe")\r
8 \r
9 (defun run-convert (arguments in)\r
10   "Return output of convert"\r
11   (let* ((p (sb-ext:run-program *convert* arguments\r
12                                       :wait nil\r
13                                       :input :stream\r
14                                       :output :stream))\r
15          (pin (sb-ext:process-input p))\r
16          (pou (sb-ext:process-output p))\r
17          (ret '()))\r
18     (loop for byte across in do\r
19          (progn\r
20            (format t "doing~%")\r
21            (write-byte byte pin)\r
22            (loop while (listen pou) do\r
23                 ;; this read should never fail and never be eof\r
24                 (format t "reading 1~%")\r
25                 (push (read-byte pou) ret))))\r
26     (format t "finishing out, closing~%")\r
27     (finish-output pin)\r
28     (close pin)\r
29     (let ((c 0))\r
30       (loop while (setf c (read-byte pou nil nil)) do\r
31            (format t "reading 2~%")\r
32            (push c ret)))\r
33     ret))\r
34 \r
35 (defun resize-image (bytes x y)\r
36   (run-convert (list "-scale" (format nil "~dx~d" x y) "-" "-") bytes))