Description

Chicken bindings for the epeg thumbnailer library.

Author

Peter Bex

Version

Requires

Usage

(require-extension epeg)

Download

epeg.egg

Documentation

General overview

Epeg works by first opening a file, then setting the desired properties of the scaled image. Upon encoding, these properties are taken into account. Decoding is deferred until encoding of the new image takes place for optimal speed.

Image creation, destruction and friends

procedure: (epeg:file-open filename)
Returns a new epeg:image object which describes the image stored in the file filename.
procedure: (epeg:image? img)
Determine if the given img object is an epeg image.
procedure: (epeg:close img)
Destroy the image and close the associated file.
procedure: (epeg:encode img)
Store the image to the file as determined by epeg:file-output-set!. For other properties of the image, see below.

Image properties

procedure: (epeg:size-get img)
Returns 2 values: the width and height of the original image.
procedure: (epeg:file-output-set! img filename)
Set the output file for subsequent calls to epeg:encode.
procedure: (epeg:decode-size-set! img width height)
Set the size of the new image, in pixels. The original image is decoded into this size.
procedure: (epeg:decode-bounds-set! img x y width height)
Set the bounds of the image to be decoded. This is like cropping the image upon loading it.
procedure: (epeg:decode-colorspace-set! img colorspace)
Set the colorspace for decoding. This is one of the following:
  • epeg:colorspace-gray8
  • epeg:colorspace-yuv8
  • epeg:colorspace-rgb8
  • epeg:colorspace-bgr8
  • epeg:colorspace-rgba8
  • epeg:colorspace-bgra8
  • epeg:colorspace-argb32
  • epeg:colorspace-cmyk
procedure: (epeg:colorspace-get img)
Returns the current colorspace value to use for decoding.The values returned by this is any of the constantsdescribed under epeg:decode-colorspace-set!.
procedure: (epeg:comment-set! img comment)
Set the comment string for encoding. By default, this is not written to the thumbnail! Use epeg:thumbnail-comments-enable to enable this.
procedure: (epeg:comment-get img)
Returns the comment string to use for encoding, or #f if none was set.
procedure: (epeg:thumbnail-comments-enable img)
Enable comment field for the thumbnail.
procedure: (epeg:thumbnail-comments-enable img)
Disable comment field for the thumbnail. The default setting for comments is disabled.
procedure: (epeg:thumbnail-comments-get img)
Returns the uri field, width, height and mimetype of the thumbnail that will be written.
procedure: (epeg:quality-set! img percentage)
Set the thumbnail's image quality (0 - 100).
procedure: (epeg:trim img)
Undocumented

Pixel query functions

Currently, the pixel query functions have been disabled.

Examples

;;
;; Almost literal translation of src/bin/epeg_main.c in the epeg distribution.
;;
(use epeg)

(unless (= (length (argv)) 3)
	(printf "Usage: ~A input.jpg thumb.jpg\n" (car (argv)))
	(exit 0))

; This will throw an i/o file exception if the file can't be opened
(define im (epeg:file-open (list-ref (argv) 1)))

(let ((com (epeg:comment-get im)))
    (when com (printf "Comment: ~A\n" com)))

(call-with-values
    (lambda ()
      (epeg:thumbnail-comments-get im))
  (lambda (uri width height mimetype)
    (when mimetype
	  (printf "Thumb Mimetype: ~A\n" mimetype)
	  (when uri
	    (printf "Thumb URI: ~A\n" uri))
	  (printf "Thumb Mtime: \n")
	  (printf "Thumb Width: ~A\n" width)
	  (printf "Thumb Height: ~A\n" height))))

(call-with-values
    (lambda ()
      (epeg:size-get im))
  (lambda (width height)
    (printf "Image size: ~Ax~A\n" width height)))

(epeg:decode-size-set! im 128 96)
(epeg:quality-set! im 80)
(epeg:thumbnail-comments-enable im)
(epeg:comment-set! im "Smelly pants!")
(epeg:file-output-set! im (list-ref (argv) 2))
(epeg:encode im)
(epeg:close im)  ; Not required

(exit 0)

License

Copyright (c) 2004 - 2006, Peter Bex (peter.bex@xs4all.nl)
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.
2. 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.
3. Neither the name of Peter Bex nor the names of any contributors may
   be used to endorse or promote products derived from this software
   without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY PETER BEX 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 FOUNDATION 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.