Chicken bindings for the imlib2 image library.
Note that currently not all imlib2 functionality has been added to this egg.
Font loading[procedure] (font-load filename size) => font
Load and return a true type font from file filename sized size pixels. This respects the system's font path.
Image creation, destruction and friends[procedure] (image-create width height) => image
Returns a new imlib2 image object which represents a transparent image of the given size.[procedure] (image? img) => boolean
Determine if img is an imlib image.[procedure] (image-destroy img)
Destroy the given image object.[procedure] (image-clone img) => image
Create a fresh copy of the image object img.[procedure] (image-load filename) => image
Returns a new imlib image object which represents the image stored in the file filename. This automatically uses the correct loader, as determined by Imlib2 on the basis of the file's extension.[procedure] (image-save img filename)
Store the imlib image object represented by img in the file filename. The right loader is automatically selected by Imlib2 if you haven't set it explicitly with image-format-set!.[procedure] (make-image pointer)
Construct an imlib image object for pointer.
Image properties[procedure] (image-format img) => string
Request the currently set format for the image, or #f if no format has been associated with it yet.[procedure] (image-format-set! img format)
Explicitly set the file format on the image for subsequent calls to image-save. The format argument is passed to the loaders in the same way a file extension would be.[procedure] (image-width img) => integer
Returns the width of the supplied image, in pixels.[procedure] (image-height img) => integer
Returns the height of the supplied image, in pixels.[procedure] (image-filename img) => string
Returns the original filename for the image, if it was loaded from a file. Otherwise it returns #f.[procedure] (image-alpha? img) => boolean
Does the image have an alpha layer?[procedure] (image-alpha-set! img value)
Enable or disable alpha layer support for the image.[procedure] (image-track-changes-on-disk img)
From now on, track changes on disk to the file that is associated with img. By default, all images are cached by imlib2 in such a way that closing and reopening it just pulls it from cache instead of really loading it. Unfortunately, there's no way to request the status of this option or disable it.[procedure] (image-get-data-for-reading-only img)
Get a read-only pointer on img's content data.
Image manipulation operations
All these operations create a copy of the image. This can eat a lot of memory if you're not careful. Use the methods ending with a bang if you just want to destructively update an existing image.
Blending[procedure] (image-blend img src-img #!key (merge-alpha #t) (src-x 0) (src-y 0) (src-width (image-width src-img)) (src-height (image-height src-img)) (dest-x 0) (dest-y 0) (dest-width (image-width src-img)) (dest-height (image-height src-img)))
[procedure] (image-blend! img src-img #!key (merge-alpha #t) (src-x 0) (src-y 0) (src-width (image-width src-img)) (src-height (image-height src-img)) (dest-x 0) (dest-y 0) (dest-width (image-width src-img)) (dest-height (image-height src-img)))
Blend src-img onto img, possibly cropping and scaling it. The default behavior is to blend src-img in total and in its original size onto the top left corner of img.
Orientation[procedure] (image-flip-horizontal img) => image
[procedure] (image-flip-horizontal! img) => image
Horizontally flip img.
[procedure] (image-flip-vertical img) => image
[procedure] (image-flip-vertical! img) => image
Vertically flip img.
[procedure] (image-flip-diagonal img) => image
[procedure] (image-flip-diagonal! img) => image
Diagonally flip img. This works like transposing a matrix.[procedure] (image-orientate img orientation) => image
[procedure] (image-orientate! img orientation) => image
Orientate img. According to imlib2 documentation, this procedure rotates the image by 90 degrees orientation times. However, the procedure accepts values between 0 and 7, inclusive. What values 4-7 do, I'm not really sure of. They appear to rotate the image (mod orientation 3) times 90 degrees, but flip it as well.
Texture/retouching procedures[procedure] (image-sharpen img radius) => image
[procedure] (image-sharpen! img radius) => image
Sharpen img. The radius argument is an integer number indicating the degree of sharpening that has to take place. I am not sure what a negative value means, but it is allowed.[procedure] (image-blur img radius) => image
[procedure] (image-blur! img radius) => image
Blur img. The radius argument is a positive integer indicating the blur matrix radius, so 0 has no effect.[procedure] (image-tile img) => image
[procedure] (image-tile! img) => image
[procedure] (image-tile-horizontal img) => image
[procedure] (image-tile-horizontal! img) => image
[procedure] (image-tile-vertical img) => image
[procedure] (image-tile-vertical! img) => image
Adjust img in such a way around the edges, such that it is suitable for use in repeating ("tiled") patterns on all sides, only horizontally or only vertically.[procedure] (image-crop img x y width height) => image
[procedure] (image-crop! img x y width height) => image
Crop img. The x and y parameters indicate the upper left pixel of the new image. The width and height parameters indicate the size of the new image. Returns #f on failure.
Note: This procedure will return an image of the requested size, but with undefined contents if you pass it arguments that lie outside the image! I am still unsure if this is a bug or feature.[procedure] (image-scale img width height)
Create a new, scaled copy of the image.[procedure] (image-crop&scale img src-x src-y src-width src-height dest-width dest-height)
Create a new, cropped and scaled copy of img. The arguments src-x, src-y, src-width and src-height indicate cropping dimensions as per image-crop, in the original image. The dest-width and dest-height arguments indicate the new image's width and height.
Pixel query procedures[procedure] (image-pixel/rgba img x y) => integer integer integer integer
Returns the RGBA (red, green, blue, alpha) color values for the image at the specified pixel coordinate as 4 values.[procedure] (image-pixel/hsva img x y) => integer integer integer integer
Returns the HSVA (hue, saturation, value, alpha) color values for the image at the specified pixel coordinate as 4 values.[procedure] (image-pixel/hlsa img x y) => integer integer integer integer
Returns the HLSA (hue, lightness, saturation, alpha) color values for the image at the specified pixel coordinate as 4 values.[procedure] (image-pixel/cmya img x y) => integer integer integer integer
Returns the CMYA (cyan, magenta, yellow, alpha) color values for the image at the specified pixel coordinate as 4 values.
Note: This could use some more work. Perhaps the procedures from the previous section should return values of these types instead.[procedure] (color? color) => boolean
Is the specified object an imlib color specifier?[procedure] (color/rgba r g b a) => color
Create a color specifier for the given RGBA values.[procedure] (color/hsva h s v a) => color
Create a color specifier for the given HSVA values.[procedure] (color/hlsa h l s a) => color
Create a color specifier for the given HLSA values.[procedure] (color/cmya c m y a) => color
Create a color specifier for the given CMYA values.
The following procedures all destructively update the image object.
Shapes and Pixels[procedure] (image-draw-pixel img color x y)
Draw a pixel in the given image on the given coordinates with the given color specifier.[procedure] (image-draw-line img color x1 y1 x2 y2)
Draw a line in the image from the coordinates (x1,y1) to (x2,y2).[procedure] (image-draw-rectangle img color x y width height)
Draw a one-pixel wide outline of a rectangle with the given color. The x and y coordinates are of the upper left corner of the rectangle.[procedure] (image-fill-rectangle img color x y width height)
Same as image-draw-rectangle, but filled in.
Text[procedure] (image-draw-text img font color x y text #!optional (direction 'to-right) (angle #f))
Draw the string text on img at coordinates x / y with color and font. Possible direction symbols are to-right, to-left, to-down, to-up and to-angle. The optional angle argument must be supplied when direction is to-angle.
- 0.17 Fix option quoting during installation, which broke on clang
- 0.16 Add image-create-using-copied-data procedure and expose some more procedures for working with raw image pointers (thanks to Andrei Barbu for the patch)
- 0.15 Bugfix release to correct the name of image-get-data-for-reading-only.
- 0.14 Expose make-image and add image-get-data-for-reading-only (thanks Andrei Barbu)
- 0.13 Convert deprecated pointer type to c-pointer so it works with new Chicken versions (thanks to Christian Kellermann).
- 0.12 Add bindings for image blending, font loading and text drawing functions
- 0.9 Always compile without X. The X specific functions were not handled by this egg anyway.
- 0.8 Fixed setup script so it uses imlib2-config to determine CFLAGS/LDFLAGS and works for xorg (X11R7)
- 0.7 Port to Chicken 4, procedure renaming (removal of prefix), switch to wiki for documentation
- 0.6 Fix for wrong variable names.
- 0.5 Fix define/clone bug; thanks to Graham Fawcett
- 0.4 Fix finalizer bug; set correct context before freeing
- 0.3 Set GC finalizers on all procedures that create new imlib objects and allow linking against imlib2 that was compiled without X and converted documentation to eggdoc.
- 0.2 imlib:alpha-set! wasn't exported
- 0.1 Beta release
Copyright (c) 2005-2011, Peter Bex All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.