imlib2

  1. imlib2
    1. Description
    2. Author
    3. Maintainer
    4. Repository
    5. Requirements
    6. Documentation
      1. Font loading
      2. Image creation, destruction and friends
      3. Image properties
      4. Image manipulation operations
        1. Blending
        2. Orientation
        3. Texture/retouching procedures
      5. Pixel query procedures
      6. Color specifiers
      7. Drawing procedures
        1. Shapes and Pixels
        2. Text
    7. Changelog
    8. License

Description

Chicken bindings for the imlib2 image library.

Author

Peter Bex

Maintainer

Vasilij Schneidermann

Repository

This egg is hosted on the CHICKEN Subversion repository:

https://anonymous@code.call-cc.org/svn/chicken-eggs/release/5/imlib2

If you want to check out the source code repository of this egg and you are not familiar with Subversion, see this page.

Requirements

None

Documentation

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.

Color specifiers

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.

Drawing procedures

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.

Changelog

License

 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.