How to resize an image with image-magick

Discussion of Common Lisp

How to resize an image with image-magick

Postby Alex Ati » Sun Aug 17, 2008 7:54 am

Hello!

I'm trying to use cl-magick to resize an image file, but i can't find how to.
After asdf-installing cl-magick on an ubuntu distro, the bindings couldn't find the alien functions. I managed to spot the error; certain .so files assumed to be existing actually weren't (they were .so.10 and the like), so a couple of ln -s solved the problem.

Thing is, after that, i can't find any documentation. Seems that the creator is not very fond of it. I toyed a while with the slime completion, and found some promising function names, like cl-magick:magickreadimagefile and cl-magick:magickresizeimage. But i can't manage to use them; reading somewhere i understood that i have to pass the function a file descriptor, instead of a stream or a file name. I feel i have used all my resources, and can't get around this one. Could someone please help me find a solution? Even if it is just some directions to doc (although if it were accompanied by a couple of code lines solving the problem or something related it would be awesome)

Thanks a lot!

Alex Ati

PS. The perfect post reply would help future third persons looking to resolve this or similar problems. Mind the forum!
Alex Ati
 
Posts: 5
Joined: Thu Jul 03, 2008 8:45 am

Re: How to resize an image with image-magick

Postby Ramarren » Sun Aug 17, 2008 10:00 am

cl-magick is a very thin wrapper around imagemagick, which means that to use it you have to refer to ImageMagick documentation. I have used it very briefly some time ago, so I don't remember much, but I think resizing an image would go something like that:

Code: Select all
(defun resize (file out-file w h)
  (let ((wand (newmagickwand)))
    (cffi:with-foreign-strings ((file file)
                                (out-file out-file))
     (magickreadimage wand file)
     (magickresizeimage wand w h filtertypes-lanczos 1d0)
     (magickwriteimage wand out-file))))


As I have said cl-magick is so thin, and using uffi which apparently did not have automatic string wrapping, that you have to allocate foreign strings yourself. I used here cffi-uffi-compat package to load cl-magick, if one were using uffi only it must have some equivalent.

If you want to actually use the image data in the Lisp program then it becomes more complicated... I would suggest using FFA and looking at magickgetimagepixels functions, and handle image data as a Lisp array. Other that that, using ImageMagick from Lisp with cl-magick bindings would be just like using it from C, so you should look for some tutorials about that. I don't know if someone wrote better, more lispy bindings, since I didn't need them lately.
Ramarren
 
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland


Return to Common Lisp

Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests

cron