pg_image 0.3

This extension provides an IMAGE datatype for the storage of bitmap images, which verifies that the image data is in a recognized format (PNG or JPEG) and provides accessor functions for the image metadata (format, width, height) as well as the image data itself.

Planned features include conversion between formats, cropping and scaling, annotating with text, and compositing of multiple images.

Depends on the GD library for image loading and manipulation.

Compatible with PostgreSQL 9.2 and 9.3beta2.


The IMAGE datatype can be added to a database using the Postgres extension mechanism:


Once installed, the pg_image extension provides the IMAGE datatype. The type I/O functions use the data: URI format (commonly used to include inline images in HTML and CSS documents) for the image data.

Several functions and operators are provided for working with values of type IMAGE:

Function/Operator   Returns     Description
------------------  ----------  -----------------------------------------------
image(BYTEA, TEXT)  IMAGE       Construct an IMAGE value from raw image data
                                in JPEG or PNG format.  Must supply the image's
                                mimetype ("image/png" or "image/jpeg").
width(IMAGE)        INTEGER     Width (in pixels) of the image.
height(IMAGE)       INTEGER     Height (in pixels) of the image.
filesize(IMAGE)     INTEGER     File size (in bytes) of the image.
mimetype(IMAGE)     TEXT        Image's mimetype ("image/png" or "image/jpeg").
imagedata(IMAGE)    BYTEA       The raw image data, in JPEG or PNG format.
image_hash(IMAGE)   INT4        Hash value.
= (IMAGE, IMAGE)    BOOLEAN     Equality.
<>(IMAGE, IMAGE)    BOOLEAN     Inequality.


To build (and install):

make install
make installcheck

Authors and Credits

Andrew Tipton andrew@kiwidrew.com

The base64 encoding/decoding functions are lightly modified copies of the excellent Postgres functions by the same name. (Which are unfortunately not exposed in the public API except through a high-level wrapper.)

Thanks to malloc() labs limited (www.malloclabs.com) for supporting the development of this module.


This Postgres extension is free software; you may use it under the same terms as Postgres itself.

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.