12. Image Module |
CLASS Image.Image |
The main object of the Image module, this object is used as drawing area, mask or result of operations.
basic:
clear ,
clone ,
create ,
xsize ,
ysize
plain drawing:
box ,
circle ,
getpixel ,
line ,
setcolor ,
setpixel ,
threshold ,
polyfill
operators:
`& ,
`* ,
`+ ,
`- ,
`== ,
`> ,
`< ,
`|
pasting images:
paste ,
paste_alpha ,
paste_alpha_color ,
paste_mask
getting subimages, scaling, rotating:
autocrop ,
clone ,
copy ,
dct ,
mirrorx ,
rotate ,
rotate_ccw ,
rotate_cw ,
rotate_expand ,
scale ,
skewx ,
skewx_expand ,
skewy ,
skewy_expand
calculation by pixels:
apply_matrix ,
change_color ,
color ,
distancesq ,
grey ,
invert ,
modify_by_intensity ,
outline
select_from ,
rgb_to_hsv ,
hsv_to_rgb ,
average , max , min , sum , sumf , find_min , find_max
special pattern drawing:
noise ,
turbulence ,
test ,
tuned_box ,
gradients ,
random
Image , Image.Font , Image.Colortable , Image.X
object paste(object image)
object paste(object image, int x, int y)
Pastes a given image over the current image.
image to paste (may be empty, needs to be an image object)
where to paste the image; default is 0,0
the object called
paste_mask , paste_alpha , paste_alpha_color
object paste_alpha(object image, int alpha)
object paste_alpha(object image, int alpha, int x, int y)
Pastes a given image over the current image, with the specified alpha channel value.
An alpha channel value of 0 leaves nothing of the original image in the paste area, 255 is meaningless and makes the given image invisible.
image to paste
alpha channel value
where to paste the image; default is 0,0
the object called
paste_mask , paste , paste_alpha_color
object paste_alpha_color(object mask)
object paste_alpha_color(object mask, int x, int y)
object paste_alpha_color(object mask, int r, int g, int b)
object paste_alpha_color(object mask, int r, int g, int b, int x, int y)
object paste_alpha_color(object mask, Color color)
object paste_alpha_color(object mask, Color color, int x, int y)
Pastes a given color over the current image, using the given mask as opaque channel.
A pixel value of 255 makes the result become the color given, 0 doesn't change anything.
The masks red, green and blue values are used separately. If no color are given, the current is used.
mask image
what color to paint with; default is current
where to paste the image; default is 0,0
the object called
paste_mask , paste_alpha , paste_alpha_color
object paste_mask(object image, object mask)
object paste_mask(object image, object mask, int x, int y)
Pastes a given image over the current image, using the given mask as opaque channel.
A pixel value of 255 makes the result become a pixel from the given image, 0 doesn't change anything.
The masks red, green and blue values are used separately.
image to paste
mask image
where to paste the image; default is 0,0
the object called
paste , paste_alpha , paste_alpha_color
object dct(int newx, int newy)
Scales the image to a new size.
Method for scaling is rather complex; the image is transformed via a cosine transform, and then resampled back.
This gives a quality-conserving upscale, but the algorithm used is n*n+n*m, where n and m is pixels in the original and new image.
Recommended wrapping algorithm is to scale overlapping parts of the image-to-be-scaled.
This functionality is actually added as an true experiment, but works...
new image size in pixels
the new image object
Do NOT use this function if you don't know what you're dealing with! Read some signal theory first...
It write's dots on stderr, to indicate some sort of progress. It doesn't use any fct (compare: fft) algorithms.
object apply_curve(object array(int(0..255)
object apply_curve(object array(int(0..255)
object apply_curve(object stringchannel, object array(int(0..255)
Apply a lookup-table on all pixels in an image. If only one curve is passed, use the same curve for red, green and blue. If 'channel' is specified, the curve is only applied to the specified channel.
An array with 256 elements, each between 0 and 255. It is used as a look-up table, if the pixel value is 2 and curve[2] is 10, the new pixel value will be 10.
one of "red", "green", "blue", "value", "saturation" and "hue".
a new image object
gamma , `* , modify_by_intensity
object apply_matrix(array(array(int|array(int))) matrix)
object apply_matrix(array(array(int|array(int))) matrix, int r, int g, int b)
object apply_matrix(array(array(int|array(int))) matrix, int r, int g, int b, int|float div)
Applies a pixel-transform matrix, or filter, to the image.
2 2
pixel(x,y)= base+ k ( sum sum pixel(x+k-1,y+l-1)*matrix(k,l) )
k=0 l=0
1/k is sum of matrix, or sum of matrix multiplied with div. base is given by r,g,b and is normally black.
blur (ie a 2d gauss function):
({({1,2,1}), ({2,5,2}), ({1,2,1})}) |
![]() |
![]() |
original | ||
sharpen (k>8, preferably 12 or 16):
({({-1,-1,-1}), ({-1, k,-1}), ({-1,-1,-1})}) |
![]() | |
edge detect:
({({1, 1,1}), ({1,-8,1}), ({1, 1,1})}) |
![]() | |
horisontal edge detect (get the idea):
({({0, 0,0}), ({1,-2,1}), ({0, 0,0})}) |
![]() | |
emboss (might prefer to begin with a grey image):
({({2, 1, 0}), ({1, 0,-1}), ({0,-1,-2})}), 128,128,128, 3 |
![]() |
![]() |
greyed |
This function is not very fast.
the matrix; innermost is a value or an array with red, green, blue values for red, green, blue separation.
base level of result, default is zero
division factor, default is 1.0.
the new image object
object autocrop()
object autocrop(int border)
object autocrop(int border, Color color)
object autocrop(int border, int left, int right, int top, int bottom)
object autocrop(int border, int left, int right, int top, int bottom, Color color)
array(int) find_autocrop()
array(int) find_autocrop(int border)
array(int) find_autocrop(int border, int left, int right, int top, int bottom)
Removes "unneccesary" borders around the image, adds one of its own if wanted to, in selected directions.
"Unneccesary" is all pixels that are equal -- ie if all the same pixels to the left are the same color, that column of pixels are removed.
The find_autocrop() function simply returns x1,y1,x2,y2 for the kept area. (This can be used with copy later.)
which borders to scan and cut the image;
a typical example is removing the top and bottom unneccesary
pixels:
img=img->autocrop(0, 0,0,1,1);
the new image object
copy
object bitscale(float factor)
object bitscale(float xfactor, float yfactor)
scales the image with a factor, without smoothing. This routine is faster than scale, but gives less correct results
![]() |
![]() |
![]() |
original | bitscale(0.75) | scale(0.75) |
factor to use for both x and y
separate factors for x and y
the new image object
object bitscale(int newxsize, int newysize)
object bitscale(0, int newysize)
object bitscale(int newxsize, 0)
scales the image to a specified new size, if one of newxsize or newysize is 0, the image aspect ratio is preserved.
new image size in pixels
the new image object
resulting image will be 1x1 pixels, at least
string blur(int no_pass)
A special case of apply_matrix that creates a blur effect. About four times faster than the generic apply_matrix. @[no_pass] is the number of times the blur matrix is applied.
![]() |
![]() |
![]() |
original | blur(1) | blur(5) |
apply_matrix , grey_blur
object box(int x1, int y1, int x2, int y2)
object box(int x1, int y1, int x2, int y2, int r, int g, int b)
object box(int x1, int y1, int x2, int y2, int r, int g, int b, int alpha)
Draws a filled rectangle on the image.
![]() |
![]() |
![]() |
original | ->box (40,10, 10,80, 0,255,0) |
->box (40,10, 10,80, 255,0,0,75) |
box corners
color of the box
alpha value
the object called
string cast(string type)
Cast the image to another datatype. Currently supported are string ("rgbrgbrgb...") and array (double array of Image.Color objects).
Image.Color , Image.X
object change_color(int tor, int tog, int tob)
object change_color(int fromr, int fromg, int fromb, object inttor, int tog, int tob)
Changes one color (exakt match) to another. If non-exakt-match is preferred, check distancesq and paste_alpha_color .
destination color and next current color
source color, default is current color
a new (the destination) image object
object circle(int x, int y, int rx, int ry)
object circle(int x, int y, int rx, int ry, int r, int g, int b)
object circle(int x, int y, int rx, int ry, int r, int g, int b, int alpha)
Draws a circle on the image. The circle is not antialiased.
![]() |
![]() |
original | ->circle (50,50, 30,50, 0,255,255) |
circle center
circle radius in pixels
color
alpha value
the object called
void clear()
void clear(int r, int g, int b)
void clear(int r, int g, int b, int alpha)
gives a new, cleared image with the same size of drawing area
![]() |
![]() |
original | ->clear (0,128,255) |
color of the new image
new default alpha channel value
copy , clone
object clone()
object clone(int xsize, int ysize)
object clone(int xsize, int ysize, int r, int g, int b)
object clone(int xsize, int ysize, int r, int g, int b, int alpha)
Copies to or initialize a new image object.
![]() |
![]() |
![]() |
original | clone | clone(50,50) |
size of (new) image in pixels, called image is cropped to that size
current color of the new image, default is black. Will also be the background color if the cloned image is empty (no drawing area made).
new default alpha channel value
the new object
copy , create
object color()
object color(int value)
object color(int r, int g, int b)
Colorize an image.
The red, green and blue values of the pixels are multiplied with the given value(s). This works best on a grey image...
The result is divided by 255, giving correct pixel values.
If no arguments are given, the current color is used as factors.
![]() |
![]() |
original | ->color(128,128,255); |
red, green, blue factors
factor
the new image object
grey , `* , modify_by_intensity
object copy()
object copy(int x1, int y1, int x2, int y2)
object copy(int x1, int y1, int x2, int y2, int r, int g, int b)
object copy(int x1, int y1, int x2, int y2, int r, int g, int b, int alpha)
Copies this part of the image. The requested area can be smaller, giving a cropped image, or bigger - the new area will be filled with the given or current color.
![]() |
![]() |
![]() |
original | ->copy (5,5, XSIZE-6,YSIZE-6) |
->copy (-5,-5, XSIZE+4,YSIZE+4, 10,75,10) |
The requested new area. Default is the old image size.
color of the new image
new default alpha channel value
a new image object
clone (void) and copy (void) does the same operation
clone , autocrop
void Image.Image()
void Image.Image(int xsize, int ysize)
void Image.Image(int xsize, int ysize, Color color)
void Image.Image(int xsize, int ysize, int r, int g, int b)
void Image.Image(int xsize, int ysize, int r, int g, int b, int alpha)
void Image.Image(int xsize, int ysize, string method, method ...)
Initializes a new image object.
![]() |
![]() |
Image.Image (XSIZE,YSIZE) |
Image.Image (XSIZE,YSIZE,255,128,0) |
The image can also be calculated from some special methods, for convinience:
channel modes; followed by a number of 1-char-per-pixel strings
or image objects (where red channel will be used),
or an integer value:
"grey" : make a grey image (needs 1 source: grey)
"rgb" : make an rgb image (needs 3 sources: red, green and blue)
"cmyk" : make a rgb image from cmyk (cyan, magenta, yellow, black)
generate modes; all extra arguments is given to the
generation function. These has the same name as the method:
"test ,"
"gradients "
"noise "
"turbulence "
"random "
"randomgrey "
specials cases:
"tuned_box " (coordinates is automatic)
size of (new) image in pixels
background color (will also be current color), default color is black
default alpha channel value
SIGSEGVS can be caused if the size is too big, due to unchecked overflow - (xsize*ysize)&MAXINT is small enough to allocate.
copy , clone , Image.Image
object distancesq()
object distancesq(int r, int g, int b)
Makes an grey-scale image, for alpha-channel use.
The given value (or current color) are used for coordinates in the color cube. Each resulting pixel is the distance from this point to the source pixel color, in the color cube, squared, rightshifted 8 steps:
p = pixel color
o = given color
d = destination pixel
d.red=d.blue=d.green=
((o.red-p.red)²+(o.green-p.green)²+(o.blue-p.blue)²)>>8
![]() |
![]() |
![]() |
![]() |
original | distance² to cyan | ...to purple | ...to yellow |
red, green, blue coordinates
the new image object
select_from
object gamma(float g)
object gamma(float gred, object floatggreen, object floatgblue)
Calculate pixels in image by gamma curve.
Intensity of new pixels are calculated by:
i' = i^g
For example, you are viewing your image on a screen with gamma 2.2. To correct your image to the correct gamma value, do something like:
my_display_image(my_image()->gamma(1/2.2);
gamma value
a new image object
grey , `* , color
array(int) getpixel(int x, int y)
position of the pixel
color of the requested pixel -- ({int red,int green,int blue})
int gradients(array(int) point, object ...)
int gradients(array(int) point, object ..., object floatgrad)
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
original | 2 color gradient |
10 color gradient |
3 colors, grad=4.0 |
3 colors, grad=1.0 |
3 colors, grad=0.25 |
the new image
object grey()
object grey(int r, int g, int b)
Makes a grey-scale image (with weighted values).
![]() |
![]() |
![]() |
original | ->grey(); | ->grey(0,0,255); |
weight of color, default is r=87,g=127,b=41, which should be pretty accurate of what the eyes see...
the new image object
color , `* , modify_by_intensity
object grey_blur(int no_pass)
Works like blur, but only operates on the r color channel. A faster alternative to blur for grey scale images. @[no_pass] is the number of times the blur matrix is applied.
![]() |
![]() |
![]() |
original | grey_blur(1) | grey_blur(5) |
blur
object rgb_to_hsv()
object hsv_to_rgb()
Converts RGB data to HSV data, or the other way around. When converting to HSV, the resulting data is stored like this: pixel.r = h; pixel.g = s; pixel.b = v;
When converting to RGB, the input data is asumed to be placed in the pixels as above.
![]() |
![]() |
![]() |
original | ->hsv_to_rgb(); | ->rgb_to_hsv(); |
![]() |
![]() |
![]() |
tuned box (below) | the rainbow (below) | same, but rgb_to_hsv() |
HSV to RGB calculation:
in = input pixel
out = destination pixel
h=-pos*c_angle*3.1415/(float)NUM_SQUARES;
out.r=(in.b+in.g*cos(in.r));
out.g=(in.b+in.g*cos(in.r + pi*2/3));
out.b=(in.b+in.g*cos(in.r + pi*4/3));
RGB to HSV calculation: Hmm.
Example: Nice rainbow.
object i = Image.Image(200,200);
i = i->tuned_box(0,0, 200,200,
({ ({ 255,255,128 }), ({ 0,255,128 }),
({ 255,255,255 }), ({ 0,255,255 })}))
->hsv_to_rgb();
the new image object
object invert()
Invert an image. Each pixel value gets to be 255-x, where x is the old value.
![]() |
![]() |
![]() |
original | ->invert(); | ->rgb_to_hsv()->invert()->hsv_to_rgb(); |
the new image object
object line(int x1, int y1, int x2, int y2)
object line(int x1, int y1, int x2, int y2, int r, int g, int b)
object line(int x1, int y1, int x2, int y2, int r, int g, int b, int alpha)
Draws a line on the image. The line is not antialiased.
![]() |
![]() |
original | ->line (50,10, 10,50, 255,0,0) |
line endpoints
color
alpha value
the object called
object map_closest(array(array(int)) colors)
object map_fast(array(array(int)) colors)
object map_fs(array(array(int)) colors)
array select_colors(int num)
Compatibility functions. Do not use!
Replacement examples:
Old code:
img=map_fs(img->select_colors(200));
New code:
img=Image.Colortable(img,200)->floyd_steinberg()->map(img);
Old code:
img=map_closest(img->select_colors(17)+({({255,255,255}),({0,0,0})}));
New code:
img=Image.Colortable(img,19,({({255,255,255}),({0,0,0})}))->map(img);
object modify_by_intensity(int r, int g, int b, int|array(int) ... vn)
Recolor an image from intensity values.
For each color an intensity is calculated, from r, g and b factors (see grey ), this gives a value between 0 and max.
The color is then calculated from the values given, v1 representing the intensity value of 0, vn representing max, and colors between representing intensity values between, linear.
![]() |
![]() |
original | ->grey()->modify_by_intensity(1,0,0, 0,({255,0,0}),({0,255,0})); |
red, green, blue intensity factors
destination color
the new image object
grey , `* , color
object outline()
object outline(int olr, int olg, int olb)
object outline(int olr, int olg, int olb, int bkgr, int bkgg, int bkgb)
object outline(array(array(int)) mask)
object outline(array(array(int)) mask, int olr, int olg, int olb)
object outline(array(array(int)) mask, int olr, int olg, int olb, int bkgr, int bkgg, int bkgb)
object outline_mask()
object outline_mask(int bkgr, int bkgg, int bkgb)
object outline_mask(array(array(int)) mask)
object outline_mask(array(array(int)) mask, int bkgr, int bkgg, int bkgb)
Makes an outline of this image, ie paints with the given color around the non-background pixels.
Default is to paint above, below, to the left and the right of these pixels.
You can also run your own outline mask.
The outline_mask function gives the calculated outline as an alpha channel image of white and black instead.
![]() |
![]() |
![]() |
original | masked through threshold |
...and outlined with red |
mask matrix. Default is ({({0,1,0}),({1,1,1}),({0,1,0})}).
outline color. Default is current.
background color (what color to outline to); default is color of pixel 0,0.
division factor, default is 1.0.
the new image object
no antialias!
object write_lsb_rgb(string what)
object write_lsb_grey(string what)
string read_lsb_rgb()
string read_lsb_grey()
These functions read/write in the least significant bit of the image pixel values. The _rgb() functions read/write on each of the red, green and blue values, and the grey keeps the same lsb on all three.
The string is nullpadded or cut to fit.
the hidden message
the current object or the read string
object select_from(int x, int y)
object select_from(int x, int y, int edge_value)
Makes an grey-scale image, for alpha-channel use.
This is very close to a floodfill.
The image is scanned from the given pixel, filled with 255 if the color is the same, or 255 minus distance in the colorcube, squared, rightshifted 8 steps (see distancesq ).
When the edge distance is reached, the scan is stopped. Default edge value is 30. This value is squared and compared with the square of the distance above.
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
35, 35, 16 | 35, 35, 32 | 35, 35, 64 | 35, 35, 96 | 35, 35, 128 | 35, 35, 192 | 35, 35, 256 |
![]() |
![]() |
original | original * select_from(35,35,200) |
originating pixel in the image
the new image object
distancesq
object setcolor(int r, int g, int b)
object setcolor(int r, int g, int b, int alpha)
set the current color
new color
new alpha value
the object called
object setpixel(int x, int y)
object setpixel(int x, int y, Image.Color c)
object setpixel(int x, int y, int r, int g, int b)
object setpixel(int x, int y, int r, int g, int b, int alpha)
![]() |
![]() |
original | ->setpixel (10,10, 255,0,0) |
position of the pixel
color
alpha value
the object called
object test()
object test(int seed)
Generates a test image, currently random gradients.
![]() |
![]() |
![]() |
original | ->test() | ...and again |
the new image
May be subject to change or cease without prior warning.
gradients , tuned_box
object threshold()
object threshold(int level)
object threshold(int r, int g, int b)
object threshold(Color color)
Makes a black-white image.
If any of red, green, blue parts of a pixel is larger then the given value, the pixel will become white, else black.
This method works fine with the grey method.
If no arguments are given, it will paint all non-black pixels white. (Ie, default is 0,0,0.)
![]() |
![]() |
![]() |
original | ->threshold(100); | ->threshold(0,100,0); |
the new image object
The above statement "any ..." was changed from "all ..." in Pike 0.7 (9906). It also uses 0,0,0 as default input, instead of current color. This is more useful.
grey
object tuned_box(int x1, int y1, int x2, int y2, array(array(int)) corner_color)
Draws a filled rectangle with colors (and alpha values) tuned between the corners.
Tuning function is (1.0-x/xw)*(1.0-y/yw) where x and y is the distance to the corner and xw and yw are the sides of the rectangle.
![]() |
![]() |
![]() |
![]() |
original | tuned box | solid tuning (blue,red,green,yellow) |
tuning transparency (as left + 255,128,128,0) |
rectangle corners
colors of the corners:
({x1y1,x2y1,x1y2,x2y2})
each of these is an array of integeres:
({r,g,b}) or ({r,g,b,alpha})
Default alpha channel value is 0 (opaque).
the object called
int xsize()
the width of the image
int ysize()
the height of the image
object mirrorx()
mirrors an image:
![]() |
![]() |
original | ->mirrorx(); |
the new image object
object mirrory()
mirrors an image:
![]() |
![]() |
original | ->mirrory(); |
object rotate(int|float angle)
object rotate(int|float angle, int r, int g, int b)
object rotate_expand(int|float angle)
object rotate_expand(int|float angle, int r, int g, int b)
Rotates an image a certain amount of degrees (360° is a complete rotation) counter-clockwise:
![]() |
![]() |
![]() |
original | ->rotate(15,255,0,0); | ->rotate_expand(15); |
The "expand" variant of functions stretches the image border pixels rather then filling with the given or current color.
This rotate uses the skewx () and skewy () functions.
the number of degrees to rotate
color to fill with; default is current
the new image object
object rotate_ccw()
rotates an image counter-clockwise, 90 degrees.
![]() |
![]() |
original | ->rotate_ccw(); |
the new image object
object rotate_cw()
rotates an image clockwise, 90 degrees.
![]() |
![]() |
original | ->rotate_cw(); |
the new image object
object scale(float factor)
object scale(0.5)
object scale(float xfactor, float yfactor)
scales the image with a factor, 0.5 is an optimized case.
factor to use for both x and y
separate factors for x and y
the new image object
object scale(int newxsize, int newysize)
object scale(0, int newysize)
object scale(int newxsize, 0)
scales the image to a specified new size, if one of newxsize or newysize is 0, the image aspect ratio is preserved.
new image size in pixels
the new image object
resulting image will be 1x1 pixels, at least
object skewx(int x)
object skewx(int yfactor)
object skewx(int x, int r, int g, int b)
object skewx(int yfactor, int r, int g, int b)
object skewx_expand(int x)
object skewx_expand(int yfactor)
object skewx_expand(int x, int r, int g, int b)
object skewx_expand(int yfactor, int r, int g, int b)
Skews an image an amount of pixels or a factor; a skew-x is a transformation:
![]() |
![]() |
![]() |
original | ->skewx(15,255,0,0); | ->skewx_expand(15); |
the number of pixels The "expand" variant of functions stretches the image border pixels rather then filling with the given or current color.
best described as: x=yfactor*this->ysize()
color to fill with; default is current
the new image object
object skewy(int y)
object skewy(int xfactor)
object skewy(int y, int r, int g, int b)
object skewy(int xfactor, int r, int g, int b)
object skewy_expand(int y)
object skewy_expand(int xfactor)
object skewy_expand(int y, int r, int g, int b)
object skewy_expand(int xfactor, int r, int g, int b)
Skews an image an amount of pixels or a factor; a skew-y is a transformation:
![]() |
![]() |
![]() |
original | ->skewy(15,255,0,0); | ->skewy_expand(15); |
The "expand" variant of functions stretches the image border pixels rather then filling with the given or current color.
the number of pixels
best described as: t=xfactor*this->xsize()
color to fill with; default is current
the new image object
array(float) average()
array(int) min()
array(int) max()
array(int) sum()
array(float) sumf()
Gives back the average, minimum, maximum color value, and the sum of all pixel's color value.
sum() values can wrap! Most systems only have 31 bits available for positive integers. (Meaning, be careful with images that have more than 8425104 pixels.)
average() and sumf() may also wrap, but on a line basis. (Meaning, be careful with images that are wider than 8425104 pixels.) These functions may have a precision problem instead, during to limits in the 'double' C type and/or 'float' Pike type.
array(int) find_min()
array(int) find_max()
array(int) find_min(int r, int g, int b)
array(int) find_max(int r, int g, int b)
Gives back the position of the minimum or maximum pixel value, weighted to grey.
weight of color, default is r=87,g=127,b=41, same as the grey () method.
object `/(object operand)
object `/(Color color)
object `/(int value)
object `%(object operand)
object `%(Color color)
object `%(int value)
Divides pixel values and creates a new image from the result or the rest.
the other image to divide with; the images must have the same size.
if specified as color or value, it will act as a whole image of that color (or value).
the new image object
It isn't possible to do a modulo 256 either. (why?)
`- , `+ , `| , `& , `* , Image.Layer
object `&(object operand)
object `&(array(int) color)
object `&(int value)
makes a new image out of the minimum pixels values
the other image to compare with; the images must have the same size.
an array in format ({r,g,b}), this is equal to using an uniform-colored image.
equal to ({value,value,value}).
the new image object
`- , `+ , `| , `* , Image.Layer
int `==(object operand)
int `==(array(int) color)
int `==(int value)
int `<(object operand)
int `<(array(int) color)
int `<(int value)
int `>(object operand)
int `>(array(int) color)
int `>(int value)
Compares an image with another image or a color.
Comparision is strict and on pixel-by-pixel basis. (Means if not all pixel r,g,b values are correct compared with the corresponding pixel values, 0 is returned.)
the other image to compare with; the images must have the same size.
an array in format ({r,g,b}), this is equal to using an uniform-colored image.
equal to ({value,value,value}).
true (1) or false (0).
`< or `> on empty ("no image") image objects or images with different size will result in an error. `== is always true on two empty image objects and always false if one and only one of the image objects is empty or the images differs in size.
a>=b and a<=b between objects is equal to !(a<b) and !(a>b), which may not be what you want (since both < and > can return false, comparing the same images).
`- , `+ , `| , `* , `&
object `*(object operand)
object `*(array(int) color)
object `*(int value)
object `*(float value)
Multiplies pixel values and creates a new image. This can be useful to lower the values of an image, making it greyer, for instance:
image=image*128+64;
the other image to multiply with; the images must have the same size.
an array in format ({r,g,b}), this is equal to using an uniform-colored image.
equal to ({value,value,value}).
the new image object
`- , `+ , `| , `& , Image.Layer
object `+(object operand)
object `+(array(int) color)
object `+(int value)
adds two images; values are truncated at 255.
the image which to add.
an array in format ({r,g,b}), this is equal to using an uniform-colored image.
equal to ({value,value,value}).
the new image object
`- , `| , `& , `* , Image.Layer
object `-(object operand)
object `-(array(int) color)
object `-(int value)
makes a new image out of the difference
the other image to compare with; the images must have the same size.
an array in format ({r,g,b}), this is equal to using an uniform-colored image.
equal to ({value,value,value}).
the new image object
`+ , `| , `& , `* , Image.Layer , min , max , `==
object `|(object operand)
object `|(array(int) color)
object `|(int value)
makes a new image out of the maximum pixels values
the other image to compare with; the images must have the same size.
an array in format ({r,g,b}), this is equal to using an uniform-colored image.
equal to ({value,value,value}).
the new image object
`- , `+ , `& , `* , Image.Layer
object orient(void|array(object) something)
array(object) orient4()
Draws images describing the orientation of the current image.
orient gives an HSV image
(run a hsv_to_rgb pass on it
to get a viewable image).
corresponding to the angle of the
orientation:
| / - \
hue= 0 64 128 192 (=red in an hsv image)
purple cyan green red
Red, green and blue channels are added
and not compared separately.
If you first use orient4 you can give its output as input to this function.
The orient4 function gives back 4 image objects, corresponding to the amount of different directions, see above.
an image or an array of the four new image objects
experimental status; may not be exact the same output in later versions
void noise(array(float|int|array(int)) colorrange)
void noise(array(float|int|array(int)) colorrange, float scale, float xdiff, float ydiff, float cscale)
Gives a new image with the old image's size, filled width a 'noise' pattern.
The random seed may be different with each instance of pike.
Example:
->noise( ({0,({255,0,0}), 0.3,({0,255,0}), 0.6,({0,0,255}), 0.8,({255,255,0})}), 0.2,0.0,0.0,1.0 );
colorrange table
default value is 0.1
default value is 0,0
default value is 1
turbulence
object random()
object random(int seed)
object randomgrey()
object random(greyint seed)
Gives a randomized image;
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
original | ->random() | ->random(17) | greyed (same again) |
color(red) (same again) |
...red channel |
Use with ->grey () or ->color () for one-color-results.
a new image
test , noise
void turbulence(array(float|int|array(int)) colorrange)
void turbulence(array(float|int|array(int)) colorrange, int octaves, float scale, float xdiff, float ydiff, float cscale)
gives a new image with the old image's size, filled width a 'turbulence' pattern
The random seed may be different with each instance of pike.
Example:
->turbulence( ({0,({229,204,204}), 0.9,({229,20,20}), 0.9,Color.black}) );
colorrange table
default value is 3
default value is 0.1
default value is 0,0
default value is 1
noise , Image.Color
object polyfill(array(int|float) ... curve)
fills an area with the current color
curve(s), ({x1,y1,x2,y2,...,xn,yn}), automatically closed.
If any given curve is inside another, it will make a hole.
Image.Image(100,100)->setcolor(255,0,0,128)->
polyfill( ({ 20,20, 80,20, 80,80 }) );
the current object
Lines in the polygon may not be crossed without the crossing coordinate specified in both lines.
Inverted lines reported on Intel and Alpha processors.
setcolor
object apply_max(array(array(int|array(int))) matrix)
object apply_max(array(array(int|array(int))) matrix, int r, int g, int b)
object apply_max(array(array(int|array(int))) matrix, int r, int g, int b, int|float div)
This is the same as apply_matrix, but it uses the maximum instead.
This function is not very fast.
the matrix; innermost is a value or an array with red, green, blue values for red, green, blue separation.
base level of result, default is zero
division factor, default is 1.0.
the new image object
experimental status; may not be exact the same output in later versions
string make_ascii(object orient1, object objectorient2, object objectorient3, object objectorient4, object int|voidxsize, object int|voidysize)
This method creates a string that looks like
the image. Example:
//Stina is an image with a cat.
array(object) Stina4=Stina->orient4();
Stina4[1]*=215;
Stina4[3]*=215;
string foo=Stina->make_ascii(@Stina4,40,4,8);
some nice acsii-art.
experimental status; may not be exact the same
output in later versions
| / - \
hue= 0 64 128 192 (=red in an hsv image)
orient , orient4
object match(int|float scale, object objectneedle)
object match(int|float scale, object objectneedle, object objecthaystack_cert, object objectneedle_cert)
object match(int|float scale, object objectneedle, object objecthaystack_avoid, object intfoo)
object match(int|float scale, object objectneedle, object objecthaystack_cert, object objectneedle_cert, object objecthaystack_avoid, object intfoo)
This method creates an image that describes the match in every pixel in the image and the needle-Image.
new pixel value =
sum( my_abs(needle_pixel-haystack_pixel))
The new image only have the red rgb-part set.
Every pixel is divided with this value. Note that a proper value here depends on the size of the neadle.
The image to use for the matching.
This image should be the same size as the image itselves. A non-white-part of the haystack_cert-image modifies the output by lowering it.
The same, but for the needle-image.
This image should be the same size as the image itselves. If foo is less than the red value in haystack_avoid the corresponding matching-calculating is not calculated. The avoided parts are drawn in the color 0,100,0.
the new image object
experimental status; may not be exact the same output in later versions
phasev , phaseh
object phaseh()
object phasev()
object phasevh()
object phasehv()
Draws images describing the phase of the current image. phaseh gives the horizontal phase and phasev the vertical phase.
phaseh gives an image
where
max falling min rising
value= 0 64 128 192
0 is set if there is no way to determine if it is rising or falling. This is done for the every red, green and blue part of the image.
Phase images can be used to create ugly effects or to find meta-information in the orginal image.
![]() |
![]() |
![]() |
![]() |
![]() |
original | phaseh() | phasev() | phasevh() | phasehv() |
the new image object
experimental status; may not be exact the same output in later versions
0 should not be set as explained above.
CLASS Image.Layer |
layers
object set_image(Image.Image image)
object set_image(Image.Image image, Image.Image alpha_channel)
object|int(0..) image()
object|int(0..) alpha()
Set/change/get image and alpha channel for the layer. You could also cancel the channels giving 0 instead of an image object.
image and alpha channel must be of the same size, or canceled.
object set_alpha_value(float value)
float alpha_value()
Set/get the general alpha value of this layer. This is a float value between 0 and 1, and is multiplied with the alpha channel.
object autocrop()
object autocrop(int(0..1) left, int(0..1) right, int(0..1) top, int(0..1) bottom)
array(int) find_autocrop()
array(int) find_autocrop(int(0..1) left, int(0..1) right, int(0..1) top, int(0..1) bottom)
This crops (of finds) a suitable crop, non-destructive crop. The layer alpha channel is checked, and edges that is transparent is removed.
(What really happens is that the image and alpha channel is checked, and edges equal the fill setup is cropped away.)
find_autocrop () returns an array of xoff,yoff,xsize,ysize, which can be fed to crop ().
A tiled image will not be cropped at all.
left...bottom arguments can be used to tell what sides cropping are ok on.
crop , Image.Image->autocrop
object set_mode(string mode)
string mode()
array(string) available_modes()
Set/get layer mode. Mode is one of these:
top layer | |
![]() | |
bottom layer | |
![]() | |
normal | |
![]() | D=L applied with alpha: D=(L*aL+S*(1-aL)*aS) / (aL+(1-aL)*aS), aD=(aL+(1-aL)*aS) |
add | |
![]() | D=L+S applied with alpha, aD=aS |
subtract | |
![]() | D=S-L applied with alpha, aD=aS |
multiply | |
![]() | D=S*L applied with alpha, aD=aS |
divide | |
![]() | D=S/L applied with alpha, aD=aS |
negdivide | |
![]() | D=1.0-S/L applied with alpha, aD=aS |
modulo | |
![]() | D=S%L applied with alpha, aD=aS |
invsubtract | |
![]() | D=L-S applied with alpha, aD=aS |
invdivide | |
![]() | D=L/S applied with alpha, aD=aS |
invmodulo | |
![]() | D=L%S applied with alpha, aD=aS |
imultiply | |
![]() | D=(1-L)*S applied with alpha, aD=aS |
idivide | |
![]() | D=S/(1-L) applied with alpha, aD=aS |
invidivide | |
![]() | D=L/(1-S) applied with alpha, aD=aS |
difference | |
![]() | D=abs(L-S) applied with alpha, aD=aS |
max | |
![]() | D=max(L,S) applied with alpha, aD=aS |
min | |
![]() | D=min(L,S) applied with alpha, aD=aS |
bitwise_and | |
![]() | D=L&S applied with alpha, aD=aS |
bitwise_or | |
![]() | D=L|S applied with alpha, aD=aS |
bitwise_xor | |
![]() | D=L^S applied with alpha, aD=aS |
replace | |
![]() | D=(L*aL+S*(1-aL)*aS) / (aL+(1-aL)*aS), aD=aS |
red | |
![]() | Dr=(Lr*aLr+Sr*(1-aLr)*aSr) / (aLr+(1-aLr)*aSr), Dgb=Sgb, aD=aS |
green | |
![]() | Dg=(Lg*aLg+Sg*(1-aLg)*aSg) / (aLg+(1-aLg)*aSg), Drb=Srb, aD=aS |
blue | |
![]() | Db=(Lb*aLb+Sb*(1-aLb)*aSb) / (aLb+(1-aLb)*aSb), Drg=Srg, aD=aS |
hardlight | |
![]() | Like photoshop hardlight layer mode, aD=aS |
replace_hsv | |
![]() | Dhsv=Lhsv apply with alpha, aD=aS |
hue | |
![]() | Dh=Lh apply with alpha, Dsv=Lsv, aD=aS |
saturation | |
![]() | Ds=Ls apply with alpha, Dhv=Lhv, aD=aS |
value | |
![]() | Dv=Lv apply with alpha, Dhs=Lhs, aD=aS |
color | |
![]() | Dhs=Lhs apply with alpha, Dv=Lv, aD=aS |
value_mul | |
![]() | Dv=Lv*Sv apply with alpha, Dhs=Lhs, aD=aS |
darken | |
![]() | Dv=min(Lv,Sv) apply with alpha, Dhs=Lhs, aD=aS |
lighten | |
![]() | Dv=max(Lv,Sv) apply with alpha, Dhs=Lhs, aD=aS |
saturate | |
![]() | Ds=max(Ls,Ss) apply with alpha, Dhv=Lhv, aD=aS |
desaturate | |
![]() | Ds=min(Ls,Ss) apply with alpha, Dhv=Lhv, aD=aS |
hls_replace | |
![]() | Dhls=Lhls apply with alpha, aD=aS |
hls_hue | |
![]() | Dh=Lh apply with alpha, Dsv=Lsv, aD=aS |
hls_saturation | |
![]() | Ds=Ls apply with alpha, Dhv=Lhv, aD=aS |
hls_lightness | |
![]() | Dl=Ll apply with alpha, Dhs=Lhs, aD=aS |
hls_color | |
![]() | Dhs=Lhs apply with alpha, Dl=Ll, aD=aS |
hls_lightness_mul | |
![]() | Dl=Ll*Sl apply with alpha, Dhs=Lhs, aD=aS |
hls_darken | |
![]() | Dl=min(Ll,Sl) apply with alpha, Dhs=Lhs, aD=aS |
hls_lighten | |
![]() | Dl=max(Ll,Sl) apply with alpha, Dhs=Lhs, aD=aS |
hls_saturate | |
![]() | Ds=max(Ls,Ss) apply with alpha, Dhl=Lhl, aD=aS |
hls_desaturate | |
![]() | Ds=min(Ls,Ss) apply with alpha, Dhl=Lhl, aD=aS |
dissolve | |
![]() | i=random 0 or 1, D=i?L:S, aD=i+aS |
behind | |
![]() | D=(S*aS+L*(1-aS)*aL) / (aS+(1-aS)*aL), aD=(aS+(1-aS)*aL); simply swap S and L |
erase | |
![]() | D=S, aD=aS*(1-aL) |
screen | |
![]() | 1-(1-S)*(1-L) applied with alpha, aD=aS |
overlay | |
![]() | (1-(1-a)*(1-b)-a*b)*a+a*b applied with alpha, aD=aS |
burn_alpha | |
![]() | aD=aL+aS applied with alpha, D=L+S; experimental, may change or be removed |
equal | |
![]() | each channel D=max if L==S, 0 otherwise, apply with alpha |
not_equal | |
![]() | each channel D=max if L!=S, 0 otherwise, apply with alpha |
less | |
![]() | each channel D=max if L<S, 0 otherwise, apply with alpha |
more | |
![]() | each channel D=max if L>S, 0 otherwise, apply with alpha |
less_or_equal | |
![]() | each channel D=max if L<=S, 0 otherwise, apply with alpha |
more_or_equal | |
![]() | each channel D=max if L>=S, 0 otherwise, apply with alpha |
logic_equal | |
![]() | logic: D=white and opaque if L==S, black and transparent otherwise |
logic_not_equal | |
![]() | logic: D=white and opaque if any L!=S, black and transparent otherwise |
logic_strict_less | |
![]() | logic: D=white and opaque if all L<S, black and transparent otherwise |
logic_strict_more | |
![]() | logic: D=white and opaque if all L>S, black and transparent otherwise |
logic_strict_less_equal | |
![]() | logic: D=white and opaque if all L<=L, black and transparent otherwise |
logic_strict_more_equal | |
![]() | logic: D=white and opaque if all L>=L, black and transparent otherwise |
available_modes () simply gives an array containing the names of these modes.
image and alpha channel must be of the same size, or canceled.
mapping(string:mixed)|string cast()
([ "xsize":int, "ysize":int, "image":image, "alpha":image, "xoffset":int, "yoffset":int, "fill":image, "fill_alpha":image "tiled":int, "mode":string ])
object clone()
Creates a copy of the called object.
the copy
void Image.Layer(object image, object alpha, string mode)
void Image.Layer(mapping info)
void Image.Layer()
void Image.Layer(int xsize, int ysize, object color)
void Image.Layer(object color)
The Layer construct either three arguments,
the image object, alpha channel and mode, or
a mapping with optional elements:
"image":image,
// default: black
"alpha":alpha,
// alpha channel object
// default: full opaque
"mode":string mode,
// layer mode, see mode .
// default: "normal"
"alpha_value":float(0.0-1.0),
// layer general alpha value
// default is 1.0; this is multiplied
// with the alpha channel.
"xoffset":int,
"yoffset":int,
// offset of this layer
"fill":Color,
"fill_alpha":Color,
// fill color, ie what color is used
// "outside" the image. default: black
// and black (full transparency).
"tiled":int(0|1),
// select tiling; if 1, the image
// will be tiled. deafult: 0, off
The layer can also be created "empty",
either giving a size and color -
this will give a filled opaque square,
or a color, which will set the "fill"
values and fill the whole layer with an
opaque color.
All values can be modified after object creation.
image and alpha channel must be of the same size.
object crop(int xoff, int yoff, int xsize, int ysize)
Crops this layer at this offset and size. Offset is not relative the layer offset, so this can be used to crop a number of layers simuntaneously.
The fill values are used if the layer is enlarged.
a new layer object
The new layer object may have the same image object, if there was no cropping to be done.
array(string) description()
Layer descriptions
object set_fill(Color color)
object set_fill(Color color, Color alpha)
object fill()
object fill_alpha()
Set/query fill color and alpha, ie the color used "outside" the image. This is mostly useful if you want to "frame" a layer.
mixed set_misc_value(object mixedwhat, object mixedto)
mixed get_misc_value(object mixedwhat)
Set or query misc. attributes for the layer.
As an example, the XCF and PSD image decoders set the 'name' attribute to the name the layer had in the source file.
object set_offset(int x, int y)
int xoffset()
int yoffset()
Set/query layer offset.
object set_tiled(int yes)
int tiled()
Set/query tiled flag. If set, the image and alpha channel will be tiled rather then framed by the fill values.
int xsize()
int ysize()
Query layer offset. This is the same as layer image/alpha image size.
CLASS Image.Font |
Short technical documentation on a font file: This object adds the text-drawing and -creation capabilities of the Image module.
For simple usage, see write and load .
struct file_head
{
unsigned INT32 cookie; - 0x464f4e54
unsigned INT32 version; - 1
unsigned INT32 chars; - number of chars
unsigned INT32 height; - height of font
unsigned INT32 baseline; - font baseline
unsigned INT32 o[1]; - position of char_head's
} *fh;
struct char_head
{
unsigned INT32 width; - width of this character
unsigned INT32 spacing; - spacing to next character
unsigned char data[1]; - pixmap data (1byte/pixel)
} *ch;
version 2:
On-disk syntax (everything in N.B.O), int is 4 bytes, a byte is 8 bits:
pos
0 int cookie = 'FONT'; or 0x464f4e54
4 int version = 2; 1 was the old version without the last four chars
8 int numchars; Always 256 in this version of the dump program
12 int height; in (whole) pixels
16 int baseline; in (whole) pixels
20 char direction; 1==right to left, 0 is left to right
21 char format; Font format
22 char colortablep; Colortable format
23 char kerningtablep; Kerning table format
24 int offsets[numchars]; pointers into the data, realative to &cookie.
[colortable]
[kerningtable]
At each offset:
0 int width; in pixels
4 int spacing; in 1/1000:th of a pixels
8 char data[]; Enough data to plot width * font->height pixels
Please note that if width is 0, there is no data.
Font formats:
id type
0 Raw 8bit data
1 RLE encoded data, char length, char data, 70% more compact than raw data
2 ZLib compressed data 60% more compact than RLE
Colortable types:
0 No colortable (the data is an alpha channel)
1 24bit RGB with alpha (index->color, 256*4 bytes, rgba)
2 8bit Greyscale with alpha (index->color, 256*2 bytes)
Kerningtable types:
0 No kerning table
1 numchars*numchars entries, each a signed char with the kerning value
2 numchar entries, each with a list of kerning pairs, like this:
int len
len * (short char, short value)
Image , Image.Image
Image.Font|int load(string filename)
Loads a font file to this font object.
Returns zero upon failure and a font object upon success.
The path to the font file.
write
void Image.Font(string filename)
Loads a font file to this font object. Similar to load() .
Image.Image write(string text, string ... more_text_lines)
Writes some text; thus creating an image object that can be used as mask or as a complete picture. One or more text lines may be provided.
text_extents , load , Image.Image->paste_mask , Image.Image->paste_alpha_color
int height()
Returns the font height.
baseline , text_extents
array(int) text_extents(string text, string ... more_text_lines)
Calculate extents of a text-image, that would be created by calling write with the same arguments. One or more lines of text may be provided.
|
write , height , baseline
void set_xspacing_scale(float scale)
void set_yspacing_scale(float scale)
Set spacing scale to write characters closer or more far away. This does not change scale of character, only the space between them.
int baseline()
Returns font baseline (pixels from top)
height , text_extents
void center()
Document this function.
void right()
Document this function.
void left()
Document this function.
CLASS Image.Colortable |
This object keeps colortable information, mostly for image re-coloring (quantization).
The object has color reduction, quantisation, mapping and dithering capabilities.
Image , Image.Image , Image.Font , Image.GIF
void Image.Colortable()
void Image.Colortable(array(array(int)) colors)
void Image.Colortable(Image.Image image, int number)
void Image.Colortable(Image.Image image, int number, array(array(int)) needed)
void Image.Colortable(int r, int g, int b)
void Image.Colortable(int r, int g, int b, object array(int)
object add(array(array(int)) colors)
object add(Image.Image image, int number)
object add(Image.Image image, int number, array(array(int)) needed)
object add(int r, int g, int b)
object add(int r, int g, int b, object array(int)
create initiates a colortable object. Default is that no colors are in the colortable.
add takes the same argument(s) as create , thus adding colors to the colortable.
The colortable is mostly a list of colors, or more advanced, colors and weight.
The colortable could also be a colorcube, with or without additional scales. A colorcube is the by-far fastest way to find colors.
Example:
ct=colortable(my_image,256); // the best 256 colors
ct=colortable(my_image,256,({0,0,0})); // black and the best other 255
ct=colortable(({({0,0,0}),({255,255,255})})); // black and white
ct=colortable(6,7,6); // a colortable of 252 colors
ct=colortable(7,7,5, ({0,0,0}),({255,255,255}),11);
// a colorcube of 245 colors, and a greyscale of the rest -> 256
list of colors
source image
number of colors to get from the image
0 (zero) gives all colors in the image.
Default value is 256.
needed colors (to optimize selection of others to these given)
this will add to the total number of colors (see argument 'number')
size of sides in the colorcube, must (of course) be equal or larger than 2 - if smaller, the cube is ignored (no colors). This could be used to have only scales (like a greyscale) in the output.
This is to add the possibility of adding a scale of colors to the colorcube; for instance a grayscale using the arguments ({0,0,0}),({255,255,255}),17, adding a scale from black to white in 17 or more steps.
Colors already in the cube is used again to add the number of steps, if possible.
The total number of colors in the table is therefore r*b*g+step1+...+stepn.
max hash size is (probably, set by a #define) 32768 entries, giving maybe half that number of colors as maximum.
object cast(string to)
cast the colortable to an array or mapping, the array consists of Image.Color objects and are not in index order. The mapping consists of index:Image.Color pairs, where index is the index (int) of that color.
example: (mapping)Image.Colortable(img)
must be "string", "array" or "mapping".
array(object) corners()
Gives the eight corners in rgb colorspace as an array. The "black" and "white" corners are the first two.
object cubicles()
object cubicles(int r, int g, int b)
object cubicles(int r, int g, int b, int accuracy)
Set the colortable to use the cubicles algorithm to lookup the closest color. This is a mostly very fast and very accurate way to find the correct color, and the default algorithm.
The colorspace is divided in small cubes, each cube containing the colors in that cube. Each cube then gets a list of the colors in the cube, and the closest from the corners and midpoints between corners.
When a color is needed, the algorithm first finds the correct cube and then compares with all the colors in the list for that cube.
example: colors=Image.Colortable(img)->cubicles();
algorithm time: between O[m] and O[m * n], where n is numbers of colors and m is number of pixels
The arguments can be heavy trimmed for the usage of your colortable; a large number (10×10×10 or bigger) of cubicles is recommended when you use the colortable repeatedly, since the calculation takes much more time than usage.
recommended values:
image size setup
100×100 cubicles(4,5,4) (default)
1000×1000 cubicles(12,12,12) (factor 2 faster than default)
In some cases, the full method is faster.
![]() |
![]() |
![]() |
original | default cubicles, 16 colors |
accuracy=200 |
Size, ie how much the colorspace is divided. Note that the size of each cubicle is at least about 8b, and that it takes time to calculate them. The number of cubicles are r*g*b, and default is 4,5,4, ie 80 cubicles. This works good for 200±100 colors.
Accuracy when checking sides of cubicles. Default is 16. A value of 1 gives complete accuracy, ie cubicle() method gives exactly the same result as full(), but takes (in worst case) 16× the time to calculate.
the object being called
this method doesn't figure out the cubicles, this is done on the first use of the colortable.
Not applicable to colorcube types of colortable.
object floyd_steinberg()
object floyd_steinberg(int bidir, int|float forward, int|float downforward, int|float down, int|float downback, int|float factor)
Set dithering method to floyd_steinberg.
The arguments to this method is for fine-tuning of the algorithm (for computer graphics wizards).
![]() |
![]() |
![]() |
original | floyd_steinberg to a 4×4×4 colorcube | floyd_steinberg to 16 chosen colors |
Set algorithm direction of forward. -1 is backward, 1 is forward, 0 for toggle of direction each line (default).
Set error correction directions. Default is forward=7, downforward=1, down=5, downback=3.
Error keeping factor. Error will increase if more than 1.0 and decrease if less than 1.0. A value of 0.0 will cancel any dither effects. Default is 0.95.
the object being called
object full()
Set the colortable to use full scan to lookup the closest color.
example: colors=Image.Colortable(img)->full();
algorithm time: O[n*m], where n is numbers of colors and m is number of pixels
the object being called
Not applicable to colorcube types of colortable.
cubicles , map
object image()
cast the colortable to an image object
each pixel in the image object is an entry in the colortable
the resulting image object
object map(object image)
object `*(object image)
object ``*(object image)
object map(string data, int xsize, int ysize)
object `*(string data, int xsize, int ysize)
object ``*(string data, int xsize, int ysize)
Map colors in an image object to the colors in the colortable, and creates a new image with the closest colors.
![]() |
![]() |
![]() |
![]() |
![]() |
no dither | |
![]() |
![]() |
![]() |
![]() |
![]() |
floyd_steinberg dither | |
![]() |
![]() |
![]() |
![]() |
![]() |
ordered dither | |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
randomcube dither |
original | 2 | 4 | 8 | 16 | 32 colors |
a new image object
Flat (not cube) colortable and not 'full ' method: this method does figure out the data needed for the lookup method, which may take time the first use of the colortable - the second use is quicker.
cubicles , full
object nodither()
Set no dithering (default).
the object being called
object ordered()
object ordered(int r, int g, int b)
object ordered(int r, int g, int b, int xsize, int ysize)
object ordered(int r, int g, int b, int xsize, int ysize, int x, int y)
object ordered(int r, int g, int b, int xsize, int ysize, int rx, int ry, int gx, int gy, int bx, int by)
Set ordered dithering, which gives a position-dependent error added to the pixel values.
![]() |
![]() |
![]() |
![]() |
original | mapped to Image.Colortable(6,6,6)-> |
||
ordered (42,42,42,2,2) |
ordered() | ordered (42,42,42, 8,8, 0,0, 0,1, 1,0) |
|
![]() |
![]() |
![]() |
![]() |
The maximum error. Default is 32, or colorcube steps (256/size).
Size of error matrix. Default is 8×8. Only values which factors to multiples of 2 and 3 are possible to choose (2,3,4,6,8,12,...).
Offset for the error matrix. x and y is for both red, green and blue values, the other is individual.
the object being called
randomcube , nodither , floyd_steinberg , create
object randomcube()
object randomcube(int r, int g, int b)
object randomgrey()
object randomgrey(int err)
Set random cube dithering. Color choosen is the closest one to color in picture plus (flat) random error; color±random(error).
The randomgrey method uses the same random error on red, green and blue and the randomcube method has three random errors.
![]() |
![]() |
![]() |
original | mapped to Image.Colortable(4,4,4)-> |
|
randomcube() | randomgrey() | |
![]() |
![]() |
![]() |
The maximum error. Default is 32, or colorcube step.
the object being called
randomgrey method needs colorcube size to be the same on red, green and blue sides to work properly. It uses the red colorcube value as default.
ordered , nodither , floyd_steinberg , create
object reduce(int colors)
object reduce_fs(int colors)
reduces the number of colors
All needed (see create ) colors are kept.
reduce_fs creates and keeps the outmost corners of the color space, to improve floyd-steinberg dithering result. (It doesn't work very well, though.)
target number of colors
the new Colortable object
this algorithm assumes all colors are different to begin with (!)
reduce_fs keeps the "corners" as "needed colors".
corners
object rigid()
object rigid(int r, int g, int b)
Set the colortable to use the "rigid" method of looking up colors.
This is a very simple way of finding the correct color. The algorithm initializes a cube with r x g x b colors, where every color is chosen by closest match to the corresponding coordinate.
This format is not recommended for exact match, but may be usable when it comes to quickly view pictures on-screen.
It has a high init-cost and low use-cost. The structure is initiated at first usage.
the object being called
Not applicable to colorcube types of colortable.
cubicles , map , full
object spacefactors(int r, int g, int b)
Colortable tuning option, this sets the color space distance factors. This is used when comparing distances in the colorspace and comparing grey levels.
Default factors are 3, 4 and 1; blue is much darker than green. Compare with Image.Image->grey ().
the object being called
This has no sanity check. Some functions may bug if the factors are to high - color reduction functions sums grey levels in the image, this could exceed maxint in the case of high factors. Negative values may also cause strange effects. *grin*
object `+(object with, object mixed...more)
sums colortables
Colortable object with colors to add
the resulting new Colortable object
object `-(object with, object mixed...more)
subtracts colortables
Colortable object with colors to subtract
the resulting new Colortable object
Module Image.Color |
This module keeps names and easy handling for easy color support. It gives you an easy way to get colors from names.
A color is here an object, containing color information and methods for conversion, see below.
Image.Color can be called to make a color object.
Image.Color() takes the following arguments:
Image.Color(string name) // "red"
Image.Color(string prefix_string) // "lightblue"
Image.Color(string hex_name) // "#ff00ff"
Image.Color(string cmyk_string) // "%17,42,0,19.4"
Image.Color(string hsv_string) // "%@327,90,32"
Image.Color(int red, int green, int blue)
The color names available can be listed by using indices
on Image.Color. The colors are available by name directly
as Image.Color.name, too:
...Image.Color.red...
...Image.Color.green...
or, maybe
import Image.Color;
...red...
...green...
...lightgreen...
Giving red, green and blue values is equal to calling Image.Color.rgb ().
The prefix_string method is a form for getting modified colors, it understands all modifiers (light , dark , bright , dull and neon ). Simply use "method"+"color"; (as in lightgreen, dullmagenta, lightdullorange).
The hex_name form is a simple #rrggbb form, as in HTML or X-program argument. A shorter form (#rgb) is also accepted. This is the inverse to the Image.Color.Color->hex () method.
The cmyk_string is a string form of giving cmyk (cyan, magenta, yellow, black) color. These values are floats representing percent.
The hsv_string is another hue, saturation, value representation, but in floats; hue is in degree range (0..360), and saturation and value is given in percent. This is not the same as returned or given to the hsv () methods!
This table lists all the different named colors available in Image.Color. The first column shows the actual color while the five following columns demonstrates the modifiers neon, light, dark, bright and dull. The color begind the name of the color is produced by calling neon()->dark()->dark()->dark() from the color object itself, i.e. Image.Color.mintcream->neon()->dark()->dark()->dark().
Image.Color["something"] will never(!) generate an error, but a zero_type 0, if the color is unknown. This is enough to give the error "not present in module", if used as Image.Color.something, though.
If you are using colors from for instance a webpage, you might want to create the color from Image.Color.guess (), since that method is more tolerant for mistakes and errors.
Image.Color() is case- and space-sensitive. Use Image.Color.guess () to catch all variants.
and subtract with a space (lower_case(x)-" ") to make sure you get all variants.
Image.Color.Color , Image.Color.guess , Image , Image.Colortable
object Image.Color.rgb(int red, object intgreen, object intblue)
object Image.Color.hsv(int hue, object intsaturation, object intvalue)
object Image.Color.cmyk(float c, float m, float y, float k)
object Image.Color.greylevel(int level)
object Image.Color.html(string html_color)
Creates a new color object from given red, green and blue, hue, saturation and value, or greylevel, in color value range. It could also be created from cmyk values in percent.
The html () method only understands the HTML color names, or the #rrggbb form. It is case insensitive.
the created object.
object Image.Color.guess(string color)
This is equivalent to Image.Color (lower_case(str)-" "), and tries the color with a prepending '#' if no corresponding color is found.
a color object or zero_type
array(string) Image.Color._indices()
array(object) Image.Color._values()
(ie as indices(Image.Color) or values(Image.Color)) indices gives a list of all the known color names, values gives there corresponding objects.
Image.Color
CLASS Image.Color.Color |
This is the color object. It has six readable variables, r, g, b, for the red, green and blue values, and h, s, v, for the hue, saturation anv value values.
int bits(object intrbits, object intgbits, object intbbits, object intrshift, object intgshift, object intbshift)
Returns the color as an integer. The first three parameters state how many bits to use for red, green and blue respectively. The last three state how many bits each colour should be shifted. For instance, Image.Color("#AABBCC")->bits(8, 8, 8, 16, 8, 0) returns the integer 11189196, that is, 0xAABBCC.
object light()
object dark()
object neon()
object bright()
object dull()
Color modification methods. These returns a new color.
method | effect | h | s | v | as |
---|---|---|---|---|---|
light | raise light level | ±0 | ±0 | +50 | ![]() ![]() ![]() ![]() |
dark | lower light level | ±0 | ±0 | -50 | ![]() ![]() ![]() ![]() |
bright | brighter color | ±0 | +50 | +50 | ![]() ![]() ![]() ![]() |
dull | greyer color | ±0 | -50 | -50 | ![]() ![]() ![]() ![]() |
neon | set to extreme | ±0 | max | max | ![]() ![]() |
light and dark lower/highers saturation when value is min-/maximised respective.
the new color object
The opposites may not always take each other out. The color is maximised at white and black levels, so, for instance Image.Color .white->light ()->dark () doesn't give the white color back, but the equal to Image.Color .white->dark (), since white can't get any light er.
array|string cast()
cast the object to an array, representing red, green and blue (equal to ->rgb ()), or to a string, giving the name (equal to ->name ()).
the name as string or rgb as array
rgb , name
array(int) rgb()
array(float) rgbf()
array(int) hsv()
array(float) hsvf()
array(float) cmyk()
int greylevel()
int greylevel(int r, object intg, object intb)
This is methods of getting information from an Image.Color.Color object.
They give an array of
red, green and blue (rgb) values (color value),
hue, saturation and value (hsv) values (range as color value),
cyan, magenta, yellow, black (cmyk) values (in percent)
or the greylevel value (range as color value).
The greylevel is calculated by weighting red, green and blue. Default weights are 87, 127 and 41, respective, and could be given by argument.
array(int) respective int
Image.Color.Color , grey
void Image.Color.Color(int r, int g, int b)
This is the main Image.Color.Color creation method, mostly for internal use.
object grey()
object grey(int red, int green, int blue)
Gives a new color, containing a grey color, which is calculated by the greylevel method.
a new Image.Color.Color object
greylevel
string hex()
string hex(int n)
string name()
string html()
Information methods.
hex () simply gives a string on the #rrggbb format. If n is given, the number of significant digits is set to this number. (Ie, n=3 gives #rrrgggbbb.)
name () is a simplified method; if the color exists in the database, the name is returned, per default is the hex () method use.
html () gives the HTML name of the color, or the hex (2) if it isn't one of the 16 HTML colors.
a new Image.Color.Color object
rgb , hsv , Image.Color
int `==(object other_color)
int `==(array(int) rgb)
int `==(int greylevel)
int `==(string name)
Compares this object to another color,
or color name. Example:
object red=Image.Color.red;
object other=Image.Color. ...;
object black=Image.Color.black;
if (red==other) ...
if (red==({255,0,0})) ...
if (black==0) ...
if (red=="red") ...
1 or 0
The other datatype (not color object) must be to the right!
rgb , grey , name
Module Image.ANY |
This method calls the other decoding methods and has some heuristics for what type of image this is.
Methods: decode , decode_alpha , _decode
Image
mapping Image.ANY._decode(string data)
object Image.ANY.decode(string data)
object Image.ANY.decode_alpha(string data)
Tries heuristics to find the correct method of decoding the data, then calls that method.
The result of _decode() is a mapping that contains
"type":image data type (ie, "image/jpeg" or similar)
"image":the image object,
"alpha":the alpha channel or 0 if N/A
Throws upon failure.
Module Image |
Image.Layer Image.lay(array(Image.Layer|mapping) layers)
Image.Layer Image.lay(array(Image.Layer|mapping) layers, int xoffset, int yoffset, int xsize, int ysize)
Combine layers.
a new layer object.
Image.Layer
mapping Image._decode(string data)
Attempts to decode data as image data. The heuristics has some limited ability to decode macbinary files as well.
array(Image.Layer) Image.decode_layers(string data, mapping|void opt)
Attempts to decode data as image layer data. Additional arguments to the various formats decode_layers method can be passed through opt .
string Image.read_file(string file)
Reads the file file and, if the file is compressed with gzip or bzip, attempts to decompress it by calling gzip and bzip2 in a Process.create_process call.
string Image.load_file(void|object|string file)
Loads in a file, which need not be an image file. If no argument is given the data will be taken from stdin. If a file object is given, it will be read to the end of the file. If a string is given the function will first attempt to load a file with that name, then try to download data with the string as URL. Zero will be returned upon failure.
mapping Image._load(void|object|string file)
Loads a file with load_file and decodes it with _decode .
Image.Layer Image.load_layer(void|object|string file)
Helper function to load an image layer from a file. If no filename is given, Stdio.stdin is used. The loaded file is decoded with _decode.
array(Image.Layer) Image.load_layers(void|object|string file, mixed|void opts)
Helper function to load all image layers from a file. If no filename is given, Stdio.stdin is used. The loaded file is decoded with decode_layers. Extra arguments to the image types layer decoder, e.g. for XCF files, can be given in the opts mapping.
Image.Image Image.load(void|object|string file)
Helper function to load an image from a file. If no filename is given, Stdio.stdin is used. The loaded file is decoded with _decode.
Image.Image Image.filled_circle(int d)
Image.Image Image.filled_circle(int xd, int yd)
Image.Layer Image.filled_circle_layer(int d)
Image.Layer Image.filled_circle_layer(int xd, int yd)
Image.Layer Image.filled_circle_layer(int d, Image.Color.Color color)
Image.Layer Image.filled_circle_layer(int xd, int yd, Image.Color.Color color)
Image.Layer Image.filled_circle_layer(int d, int r, int g, int b)
Image.Layer Image.filled_circle_layer(int xd, int yd, int r, int g, int b)
Generates a filled circle of the dimensions xd x yd (or d x d). The Image is a white circle on black background; the layer function defaults to a white circle (the background is transparent).
Module Image.SVG |
This is a glue against the librsvg-2.0 library, providing Scalable Vector Graphics (SVG) for Pike.
mapping Image.SVG.decode_header(string data, void|mapping options)
Data is the SVG data, the charset must be unicode.
If options is specified, it contains one or more of the following options
|
The result is a mapping with the following members:
|
mapping Image.SVG._decode(string data, void|mapping options)
Data is the SVG data, the charset must be unicode.
If options is specified, it contains one or more of the following options
|
The result is a mapping with the following members:
|
array(Image.Layer) Image.SVG.decode_layers(string data, void|mapping options)
Data is the SVG data, the charset must be unicode.
If options is specified, it contains one or more of the following options
|
The result is an array of Image.Layer objects. For now there is always at most one member in the array.
Image.Image Image.SVG.decode(string data, void|mapping options)
Data is the SVG data, the charset must be unicode.
If options is specified, it contains one or more of the following options
|
Returns the image member of the mapping returned by _decode
Module Image._XPM |
int(0..0) Image._XPM._xpm_write_rows(Image.Image img, Image.Image alpha, int bpc, array(string) colors, array(string) pixels)
Fills in img and alpha according to xpm data in bpc , colors and pixels .
Bytes per color. Number of bytes used to encode each color in pixels .
Array of color definitions.
A color definition is on the format "ee c #RRGGBB", where ee is a bpc long string used to encode the color, c is a literal "c", and RRGGBB is a hexadecimal RGB code.
Raw picture information.
|
array(string) Image._XPM._xpm_trim_rows(array(string) rows)
Module Image.AVS |
object Image.AVS.decode(string data)
mapping Image.AVS._decode(string data)
string Image.AVS.encode(object image)
Handle encoding and decoding of AVS-X images. AVS is rather trivial, and not really useful, but:
An AVS file is a raw (uncompressed) 24 bit image file with alpha. The alpha channel is 8 bit, and there is no separate alpha for r, g and b.
Module Image.BMP |
This submodule keeps the BMP (Windows Bitmap) encode/decode capabilities of the Image module.
BMP is common in the Windows environment.
Simple encoding:
encode
Image , Image.Image , Image.Colortable
object Image.BMP.decode(string data)
mapping Image.BMP._decode(string data)
mapping Image.BMP.decode_header(string data)
object Image.BMP.decode(string data, mapping options)
mapping Image.BMP._decode(string data, mapping options)
mapping Image.BMP.decode_header(string data, mapping options)
Decode a BMP.
decode gives an image object,
_decode gives a mapping in the format
"type":"image/x-MS-bmp",
"image":image object,
"colortable":colortable object (if applicable)
"xsize":int,
"ysize":int,
"compression":int,
"bpp":int,
"windows":int,
the encoded image as a string
Doesn't support all BMP modes. At all.
encode
string Image.BMP.encode(object image)
string Image.BMP.encode(object image, mapping options)
string Image.BMP.encode(object image, object colortable)
string Image.BMP.encode(object image, int bpp)
Make a BMP. It default to a 24 bpp BMP file, but if a colortable is given, it will be 8bpp with a palette entry.
option is a mapping that may contain:
"colortable": Image.Colortable - palette
"bpp": 1|4|8|24 - force this many bits per pixel
"rle": 0|1 - run-length encode (default is 0)
Source image.
Colortable object, shortcut for "colortable" in options.
the encoded image as a string
Doesn't support old BMP mode, only "windows" mode.
decode
Module Image.HRZ |
object Image.HRZ.decode(string data)
mapping Image.HRZ._decode(string data)
string Image.HRZ.encode(object image)
Handle encoding and decoding of HRZ images. HRZ is rather trivial, and not really useful, but:
The HRZ file is always 256x240 with RGB values from 0 to 63. No compression, no header, just the raw RGB data. HRZ is (was?) used for amatuer radio slow-scan TV.
Module Image.ILBM |
This submodule keep the ILBM encode/decode capabilities of the Image module.
Image , Image.Image , Image.Colortable
object Image.ILBM.decode(string data)
object Image.ILBM.decode(array _decoded)
object Image.ILBM.decode(array __decoded)
Decodes ILBM data and creates an image object.
the decoded image as an image object
This function may throw errors upon illegal ILBM data. This function uses __decode and _decode internally.
encode
string Image.ILBM.encode(object image)
string Image.ILBM.encode(object image, object mappingoptions)
Encodes an ILBM image.
The options argument may be a mapping containing zero or more encoding options:
normal options:
"alpha":image object
Use this image as mask
(Note: ILBM mask is boolean.
The values are calculated by (r+2g+b)/4>=128.)
"palette":colortable object
Use this as palette for pseudocolor encoding
array Image.ILBM._decode(string|array data)
Decode an ILBM image file.
Result is a mapping,
([
"image": object image,
... more ...
])
image is the stored image.
array Image.ILBM.__decode()
Decodes an ILBM image structure down to chunks and
({int xsize,int ysize, // 0: size of image drawing area
string bitmapheader, // 2: BMHD chunk
void|string colortable, // 3: opt. colortable chunk (CMAP)
void|string colortable, // 4: opt. colormode chunk (CAMG)
string body, // 5: BODY chunk
mapping more_chunks}) // 6: mapping with other chunks
the above array
May throw errors if the ILBM header is incomplete or illegal.
Module Image.NEO |
Decodes images from the Atari image editor Neochrome.
mapping Image.NEO._decode(string data)
Low level decoding of the NEO file contents in data .
|
Image.Image Image.NEO.decode(string data)
Decodes the image data into an Image.Image object.
Module Image.PCX |
object Image.PCX.decode(string data)
Decodes a PCX image.
Throws upon error in data.
string Image.PCX.encode(object image)
string Image.PCX.encode(object image, object mappingoptions)
string Image.PCX._encode(object image)
string Image.PCX._encode(object image, object mappingoptions)
Encodes a PCX image. The _encode and the encode functions are identical
The options argument may be a mapping containing zero or more encoding options:
normal options:
"raw":1
Do not RLE encode the image
"dpy":int
"xdpy":int
"ydpy":int
Image resolution (in pixels/inch, integer numbers)
"xoffset":int
"yoffset":int
Image offset (not used by most programs, but gimp uses it)
mapping Image.PCX._decode(string data)
Decodes a PCX image to a mapping.
Throws upon error in data.
Module Image.PNG |
Support for encoding and decoding the Portable Network Graphics format, PNG.
This module uses zlib.
string Image.PNG._chunk(string type, string data)
Encodes a PNG chunk.
Please read about the PNG file format.
array Image.PNG.__decode(string data)
array Image.PNG.__decode(string data, int dontcheckcrc)
Splits a PNG file into chunks.
Result is an array of arrays, or 0 if data isn't a PNG file. Each element in the array is constructed as follows.
|
Please read about the PNG file format. Support for decoding cHRM, gAMA, sBIT, hIST, pHYs, tIME, tEXt and zTXt chunks are missing.
mapping Image.PNG._decode(string|array data)
mapping Image.PNG._decode(string|array data, mapping options)
Decode a PNG image file.
|
|
Throws an error if the image data is erroneous.
Please read about the PNG file format. This function ignores any checksum errors in the file. A PNG of higher color resolution than the Image module supports (8 bit) will lose that information in the conversion.
string Image.PNG.encode(Image.Image image)
string Image.PNG.encode(Image.Image image, mapping options)
Encodes a PNG image.
|
__decode
Please read some about PNG files.
mapping Image.PNG.decode_header(string data)
Decodes only the PNG headers.
_decode
Image.Image Image.PNG.decode(string data)
Image.Image Image.PNG.decode(string data, mapping(string:mixed) options)
Decodes a PNG image. The options mapping is the as for _decode .
Throws upon error in data.
Image.Image Image.PNG.decode_alpha(string data, void|mapping(string:mixed) options)
Decodes the alpha channel in a PNG file. The options mapping is the same as for _decode .
Throws upon error in data.
Module Image.PNM |
This submodule keeps the PNM encode/decode capabilities of the Image module.
PNM is a common image storage format on unix systems, and is a very simple format.
This format doesn't use any color palette.
The format is divided into seven subformats;
P1(PBM) - ascii bitmap (only two colors)
P2(PGM) - ascii greymap (only grey levels)
P3(PPM) - ascii truecolor
P4(PBM) - binary bitmap
P5(PGM) - binary greymap
P6(PPM) - binary truecolor
Simple encoding:
encode ,
encode_binary ,
encode_ascii
Simple decoding:
decode
Advanced encoding:
encode_P1 ,
encode_P2 ,
encode_P3 ,
encode_P4 ,
encode_P5 ,
encode_P6
Image , Image.Image , Image.GIF
object Image.PNM.decode(string data)
Decodes PNM (PBM/PGM/PPM) data and creates an image object.
the decoded image as an image object
This function may throw errors upon illegal PNM data.
encode
string Image.PNM.encode(object image)
string Image.PNM.encode_binary(object image)
string Image.PNM.encode_ascii(object image)
string Image.PNM.encode_P1(object image)
string Image.PNM.encode_P2(object image)
string Image.PNM.encode_P3(object image)
string Image.PNM.encode_P4(object image)
string Image.PNM.encode_P5(object image)
string Image.PNM.encode_P6(object image)
Make a complete PNM file from an image.
encode_binary () and encode_ascii () uses the most optimized encoding for this image (bitmap, grey or truecolor) - P4, P5 or P6 respective P1, P2 or P3.
encode_P1 /encode_P4
assumes the image is black and white. Use
Image.Image->threshold () or something like
Image.Colortable ( ({({0,0,0}),({255,255,255})}) )
->floyd_steinberg()
->map(my_image)
to get a black and white image.
encode_P2 /encode_P5 assumes the image is greyscale. Use Image.Image->grey () to get a greyscale image.
the encoded image as a string
encode () is equal to encode_binary (), but may change in a future release.
decode
Module Image.PVR |
Handle encoding and decoding of PVR images.
PVR is the texture format of the NEC PowerVR system It is a rather simple, uncompressed, truecolor format.
object Image.PVR.decode(string data)
object Image.PVR.decode_alpha(string data)
mapping Image.PVR.decode_header(string data)
mapping Image.PVR._decode(string data)
decodes a PVR image
The decode_header and _decode has these elements:
"image":object - image object \- not decode_header
"alpha":object - decoded alpha /
"type":"image/x-pvr" - image type
"xsize":int - horisontal size in pixels
"ysize":int - vertical size in pixels
"attr":int - texture attributes
"global_index":int - global index (if present)
string Image.PVR.encode(object image)
string Image.PVR.encode(object image, mapping options)
encode a PVR image
options is a mapping with optional values:
"alpha":object - alpha channel
"global_index":int - global index
"vq":int(0..1) - Vector Quantification compression
Module Image.RAS |
This submodule keep the RAS encode/decode capabilities of the Image module.
Image , Image.Image , Image.Colortable
object Image.RAS.decode(string data)
Decodes RAS data and creates an image object.
the decoded image as an image object
This function may throw errors upon illegal RAS data.
encode
string Image.RAS.encode(object image)
string Image.RAS.encode(object image, object mappingoptions)
Encodes a RAS image.
The options argument may be a mapping containing zero or more encoding options:
normal options:
"palette":colortable object
Use this as palette for pseudocolor encoding
Module Image.TGA |
object Image.TGA.decode(string data)
Decodes a Targa image.
Throws upon error in data.
string Image.TGA.encode(object image)
string Image.TGA.encode(object image, object mappingoptions)
Encodes a Targa image.
The options argument may be a mapping containing zero or more encoding options:
normal options:
"alpha":image object
Use this image as alpha channel
(Note: Targa alpha channel is grey.
The values are calculated by (r+2g+b)/4.)
"raw":1
Do not RLE encode the image
object Image.TGA._decode(string data)
Decodes a Targa image to a mapping. The mapping follows this format: ([ "image":img_object, "alpha":alpha_channel ])
Throws upon error in data.
Module Image.TIM |
Handle decoding of TIM images.
TIM is the framebuffer format of the PSX game system. It is a simple, uncompressed, truecolor or CLUT format with a one bit alpha channel.
object Image.TIM.decode(string data)
object Image.TIM.decode_alpha(string data)
mapping Image.TIM.decode_header(string data)
mapping Image.TIM._decode(string data)
decodes a TIM image
The decode_header and _decode has these elements:
"image":object - image object \- not decode_header
"alpha":object - decoded alpha /
"type":"image/x-tim" - image type
"xsize":int - horisontal size in pixels
"ysize":int - vertical size in pixels
"attr":int - texture attributes
Module Image.WBMP |
WAP bitmap format - WBMP.
object Image.WBMP.decode(string image)
Document this function.
mapping Image.WBMP._decode(string image)
Document this function.
mapping Image.WBMP.decode_header(string image)
|
string Image.WBMP.encode(object image, void|mapping args)
string Image.WBMP._encode(object image, void|mapping args)
Document this function.
Module Image.X |
This submodule handles encoding and decoding of the binary formats of X11.
Image , Image.Image , Image.Colortable
object Image.X.decode_pseudocolor(string data, int width, int height, int bpp, int alignbits, int swapbytes, object colortable)
lazy support for pseudocolor ZPixmaps
currently, only byte-aligned pixmaps are supported
object Image.X.decode_truecolor(string data, int width, int height, int bpp, int alignbits, int swapbytes, int rbits, int rshift, int gbits, int gshift, int bbits, int bshift)
object Image.X.decode_truecolor_masks(string data, int width, int height, int bpp, int alignbits, int swapbytes, int rmask, int gmask, int bmask)
lazy support for truecolor ZPixmaps
currently, only byte-aligned masks are supported
string Image.X.encode_pseudocolor(object image, int bpp, int alignbits, int vbpp, object colortable)
string Image.X.encode_pseudocolor(object image, int bpp, int alignbits, int vbpp, object colortable, string translate)
the image object to encode
bits per pixel, how many bits each pixel should take
value bits per pixel; how many bits per pixel that really contains information
the number of even bits each line should be padded to
colortable to get indices for pseudocolor
translate table for colors. Length of this string should be 1<<vbpp (or 2<<vbpp if vbpp are greater than 8).
currently, only upto 16 bits pseudocolor are supported.
string Image.X.encode_truecolor(object image, int bpp, int alignbits, int swapbytes, int rbits, int rshift, int gbits, int gshift, int bbits, int bshift)
string Image.X.encode_truecolor_masks(object image, int bpp, int alignbits, int swapbytes, int rmask, int gmask, int bmask)
string Image.X.encode_truecolor(object image, int bpp, int alignbits, int swapbytes, int rbits, int rshift, int gbits, int gshift, int bbits, int bshift, object ct)
string Image.X.encode_truecolor_masks(object image, int bpp, int alignbits, int swapbytes, int rmask, int gmask, int bmask, object ct)
Pack an image into a truecolor string. You will get a string of packed red, green and blue bits; ie:
encode_truecolor(img, 12,32, 0, 3,5, 4,0, 3,8)
will give (aligned to even 32 bits for each row):
0bbbrrr0 gggg0bbb rrr0gggg 0bbb...
<--pixel 1--><--pixel 2--> <--3-->
10987654 32101098 76543210 1098... <- bit position
<-><-> <-->
| | +--- 4,0: 4 bits green shifted 0 bits
| +-------- 3,5: 3 bits red shifted 5 bits
+----------- 3,8: 3 bits blue shifted 8 bits
The above call is equal to
encode_truecolor_masks(img, 12,32, 0, 224, 15, 768)
and
encode_truecolor(img, 12,32, 0, 3,5,4,0,3,8, colortable(1<<3,1<<4,1<<3)).
The latter gives possibility to use dither algorithms,
but is slightly slower.
the image object to encode
bits per pixel, how many bits each pixel should take
the number of even bits each line should be padded to
bits for each basecolor
leftshifts for each basecolor
masks for each basecolor (xbits and gbits are calculated from this), needs to be massive (no zeroes among the ones in the mask).
colortable object (for dithering, or whatever)
swap bytes for bpp==16,24,32, swaps bits in the bytes if bpp==1, for change of byte/bitorder between client and server.
Module Image.XBM |
object Image.XBM.decode(string data)
Decodes a XBM image.
Throws upon error in data.
string Image.XBM.encode(object image)
string Image.XBM.encode(object image, object mappingoptions)
Encodes a XBM image.
The options argument may be a mapping containing zero or more encoding options.
normal options:
"name":"xbm_image_name"
The name of the XBM. Defaults to 'image'
object Image.XBM._decode(string data)
object Image.XBM._decode(string data, object mappingoptions)
Decodes a XBM image to a mapping.
Supported options:
([
"fg":({fgcolor}), // Foreground color. Default black
"bg":({bgcolor}), // Background color. Default white
"invert":1, // Invert the mask
])
Throws upon error in data.
Module Image.XCF |
object Image.XCF.decode(string data)
Decodes a XCF image to a single image object.
Throws upon error in data, you will loose quite a lot of information by doing this. See Image.XCF._decode and Image.XCF.__decode
array(object) Image.XCF.decode_layers(object stringdata)
array(object) Image.XCF.decode_layers(object stringdata, object mappingoptions)
Decodes a XCF image to an array of Image.Layer objects
The layer object have the following extra variables (to be queried using get_misc_value):
image_xres, image_yres, image_colormap, image_guides, image_parasites, name, parasites, visible, active
Takes the same argument mapping as _decode ,
mapping Image.XCF._decode(string|object data, mapping|void options)
Decodes a XCF image to a mapping, with at least an 'image' and possibly an 'alpha' object. Data is either a XCF image, or a XCF.GimpImage object structure (as received from __decode)
Supported options
([
"background":({r,g,b})||Image.Color object
"draw_all_layers":1,
Draw invisible layers as well
"draw_guides":1,
Draw the guides
"draw_selection":1,
Mark the selection using an overlay
"ignore_unknown_layer_modes":1
Do not asume 'Normal' for unknown layer modes.
"mark_layers":1,
Draw an outline around all (drawn) layers
"mark_layer_names":Image.Font object,
Write the name of all layers using the font object,
"mark_active_layer":1,
Draw an outline around the active layer
])
Throws upon error in data. For more information, see Image.XCF.__decode
object Image.XCF.__decode(string|mapping data, object mapping|voidoptions)
Decodes a XCF image to a Image.XCF.GimpImage object.
Returned structure reference
!class GimpImage
{
int width;
int height;
int compression;
int type;
int tattoo_state;
float xres = 72.0;
float yres = 72.0;
int res_unit;
Image.Colortable colormap;
Image.Colortable meta_colormap;
array(Layer) layers = ({});
array(Channel) channels = ({});
array(Guide) guides = ({});
array(Parasite) parasites = ({});
array(Path) paths = ({});
Layer active_layer;
Channel active_channel;
Channel selection;
}
!class Layer
{
string name;
int opacity;
int type;
int mode;
int tattoo;
mapping flags = ([]);
int width, height;
int xoffset, yoffset;
array (Parasite) parasites;
LayerMask mask;
Hierarchy image;
}
!class Channel
{
string name;
int width;
int height;
int opacity;
int r, g, b;
int tattoo;
Hierarchy image_data;
object parent;
mapping flags = ([]);
array (Parasite) parasites;
}
!class Hierarchy
{
Image.Image img;
Image.Image alpha;
int width;
int height;
int bpp;
}
!class Parasite
{
string name;
int flags;
string data;
}
!class Guide
{
int pos;
int vertical;
}
!class Path
{
string name;
int ptype;
int tattoo;
int closed;
int state;
int locked;
array (PathPoint) points = ({});
}
!class PathPoint
{
int type;
float x;
float y;
}
object Image.XCF.___decode(string|mapping data)
Decodes a XCF image to a mapping.
Structure reference
([
"width":int,
"height":int,
"type":int,
"properties":({
([
"type":int,
"data":string,
]),
...
}),
"layers":({
([
"name":string,
"width":int,
"height":int,
"type":type,
"properties":({
([
"type":int,
"data":string,
]),
...
}),
"mask":0 || ([
"name":string,
"width":int,
"height":int,
"properties":({
([
"type":int,
"data":string,
]),
...
}),
"image_data":([
"bpp":int,
"width":int,
"height":int,
"tiles":({
string,
...
}),
]),
]),
"image_data":([
"bpp":int,
"width":int,
"height":int,
"tiles":({
string,
...
}),
]),
]),
...
}),
"channels":({
"name":string,
"width":int,
"height":int,
"properties":({
([
"type":int,
"data":string,
]),
...
}),
"image_data":([
"bpp":int,
"width":int,
"height":int,
"tiles":({
string,
...
}),
]),
}),
])
Module Image.XWD |
This submodule keeps the XWD (X Windows Dump) decode capabilities of the Image module.
XWD is the output format for the xwd program.
Simple decoding:
decode
Advanced decoding:
_decode
Image , Image.Image , Image.PNM , Image.X
object Image.XWD.decode(string data)
Simple decodes a XWD image file.
mapping Image.XWD._decode(string data)
mapping Image.XWD.decode_header(string data)
Decodes XWD data and returns the result.
Supported XWD visual classes and encoding formats are TrueColor / ZPixmap DirectColor / ZPixmap PseudoColor / ZPixmap
If someone sends me files of other formats, these formats may be implemented. :) /mirar+pike@mirar.org
the decoded image as an image object
This function may throw errors upon illegal or unknown XWD data.
decode
Module Image.FreeType |
Pike glue for the FreeType2 library, http://www.freetype.org/
constant Image.FreeType.FACE_FLAG_SCALABLE
constant Image.FreeType.FACE_FLAG_FIXED_WIDTH
constant Image.FreeType.FACE_FLAG_SFNT
constant Image.FreeType.FACE_FLAG_HORIZONTAL
constant Image.FreeType.FACE_FLAG_VERTICAL
constant Image.FreeType.FACE_FLAG_KERNING
constant Image.FreeType.FACE_FLAG_FAST_GLYPHS
constant Image.FreeType.FACE_FLAG_MULTIPLE_MASTERS
constant Image.FreeType.FACE_FLAG_GLYPH_NAMES
constant Image.FreeType.STYLE_FLAG_ITALIC
constant Image.FreeType.STYLE_FLAG_BOLD
CLASS Image.FreeType.Face |
A FreeType font face. We recommend using the more generic font handling interfaces in Image.Fonts instead.
Image.Image write_char(int char)
int get_kerning(int l, int r)
void attach_file(string file)
Face set_size(int width, int height)
array(string) list_encodings()
void select_encoding(string|int encoding)
mapping info()
|
void Image.FreeType.Face(string font)
The path of the font file to use
Module Image.GIF |
This submodule keep the GIF encode/decode capabilities of the Image module.
GIF is a common image storage format, usable for a limited color palette - a GIF image can only contain as most 256 colors - and animations.
Simple encoding: encode , encode_trans
Advanced stuff: render_block , header_block , end_block , netscape_loop_block
Very advanced stuff: _render_block , _gce_block
Image , Image.Image , Image.Colortable
object Image.GIF.decode(string data)
object Image.GIF.decode(array _decoded)
object Image.GIF.decode(array __decoded)
Decodes GIF data and creates an image object.
the decoded image as an image object
This function may throw errors upon illegal GIF data. This function uses __decode , _decode , Image.Image->paste and Image.Image->paste_alpha internally.
encode
object Image.GIF.decode_layers(string data)
object Image.GIF.decode_layers(array _decoded)
object Image.GIF.decode_layer(string data)
object Image.GIF.decode_layer(array _decoded)
Decodes GIF data and creates an array of layers or the resulting layer.
The resulting layer may not have the same size as the gif image, but the resulting bounding box of all render chunks in the gif file. The offset should be correct, though.
encode , decode_map
mapping Image.GIF.decode_map(string|array layers)
Returns a mapping similar to other decoders _decode function.
"image":the image
"alpha":the alpha channel
"xsize":int
"ysize":int
size of image
"type":"image/gif"
file type information as MIME type
The weird name of this function (not _decode as the other decoders) is because gif was the first decoder and was written before the API was finally defined. Sorry about that. /Mirar
string Image.GIF.encode(object img)
string Image.GIF.encode(object img, int colors)
string Image.GIF.encode(object img, object colortable)
string Image.GIF.encode_trans(object img, object alpha)
string Image.GIF.encode_trans(object img, int tr_r, int tr_g, int tr_b)
string Image.GIF.encode_trans(object img, int colors, object alpha)
string Image.GIF.encode_trans(object img, int colors, int tr_r, int tr_g, int tr_b)
string Image.GIF.encode_trans(object img, int colors, object alpha, int tr_r, int tr_g, int tr_b)
string Image.GIF.encode_trans(object img, object colortable, object alpha)
string Image.GIF.encode_trans(object img, object colortable, int tr_r, int tr_g, int tr_b)
string Image.GIF.encode_trans(object img, object colortable, object alpha, int a_r, int a_g, int a_b)
string Image.GIF.encode_trans(object img, object colortable, int transp_index)
Create a complete GIF file.
The latter (encode_trans ) functions add transparency capabilities.
Example:
img=Image.Image ([...]);
[...] // make your very-nice image
write(Image.GIF.encode (img)); // write it as GIF on stdout
The image which to encode.
These arguments decides what colors the image should be encoded with. If a number is given, a colortable with be created with (at most) that amount of colors. Default is '256' (GIF maximum amount of colors).
Alpha channel image (defining what is transparent); black
color indicates transparency. GIF has only transparent
or nontransparent (no real alpha channel).
You can always dither a transparency channel:
Image.Colortable(my_alpha, ({({0,0,0}),({255,255,255})}))
->full()
->floyd_steinberg()
->map(my_alpha)
Use this (or the color closest to this) color as transparent pixels.
Encode transparent pixels (given by alpha channel image) to have this color. This option is for making GIFs for the decoders that doesn't support transparency.
Use this color no in the colortable as transparent color.
For advanced users:
Image.GIF.encode_trans(img,colortable,alpha);
is equivalent of using
Image.GIF.header_block(img->xsize(),img->ysize(),colortable)+
Image.GIF.render_block(img,colortable,0,0,0,alpha)+
Image.GIF.end_block();
and is actually implemented that way.
string Image.GIF.end_block()
This function gives back a GIF end (trailer) block.
the end block as a string.
This is in the advanced sector of the GIF support; please read some about how GIFs are packed.
The result of this function is always ";" or "\x3b", but I recommend using this function anyway for code clearity.
header_block , end_block
string Image.GIF.header_block(int xsize, int ysize, int numcolors)
string Image.GIF.header_block(int xsize, int ysize, object colortable)
string Image.GIF.header_block(int xsize, int ysize, object colortable, int background_color_index, int gif87a, int aspectx, int aspecty)
string Image.GIF.header_block(int xsize, int ysize, object colortable, int background_color_index, int gif87a, int aspectx, int aspecty, int r, int g, int b)
This function gives back a GIF header block.
Giving a colortable to this function includes a global palette in the header block.
Size of drawing area. Usually same size as in the first (or only) render block(s).
This color in the palette is the background color. Background is visible if the following render block(s) doesn't fill the drawing area or are transparent. Most decoders doesn't use this value, though.
If set, write 'GIF87a' instead of 'GIF89a' (default 0 == 89a).
Aspect ratio of pixels, ranging from 4:1 to 1:4 in increments of 1/16th. Ignored by most decoders. If any of aspectx or aspecty is zero, aspectratio information is skipped.
Add this color as the transparent color. This is the color used as transparency color in case of alpha-channel given as image object. This increases (!) the number of colors by one.
the created header block as a string
This is in the advanced sector of the GIF support; please read some about how GIFs are packed.
This GIF encoder doesn't support different size of colors in global palette and color resolution.
header_block , end_block
string Image.GIF.netscape_loop_block()
string Image.GIF.netscape_loop_block(int number_of_loops)
Creates a application-specific extention block; this block makes netscape and compatible browsers loop the animation a certain amount of times.
Number of loops. Max and default is 65535.
string Image.GIF.render_block(object img, object colortable, int x, int y, int localpalette)
string Image.GIF.render_block(object img, object colortable, int x, int y, int localpalette, object alpha)
string Image.GIF.render_block(object img, object colortable, int x, int y, int localpalette, object alpha, int r, int g, int b)
string Image.GIF.render_block(object img, object colortable, int x, int y, int localpalette, int delay, int transp_index, int interlace, int user_input, int disposal)
string Image.GIF.render_block(object img, object colortable, int x, int y, int localpalette, object alpha, int r, int g, int b, int delay, int interlace, int user_input, int disposal)
This function gives a image block for placement in a GIF file, with or without transparency. The some options actually gives two blocks, the first with graphic control extensions for such things as delay or transparency.
Example:
img1=Image.Image ([...]);
img2=Image.Image ([...]);
[...] // make your very-nice images
nct=Image.Colortable ([...]); // make a nice colortable
write(Image.GIF.header_block (xsize,ysize,nct)); // write a GIF header
write(Image.GIF.render_block (img1,nct,0,0,0,10)); // write a render block
write(Image.GIF.render_block (img2,nct,0,0,0,10)); // write a render block
[...]
write(Image.GIF.end_block ()); // write end block
// voila! A GIF animation on stdout.
The above animation is thus created:
object nct=Image.colortable(lena,32,({({0,0,0})}));
string s=GIF.header_block(lena->xsize(),lena->ysize(),nct);
foreach ( ({lena->xsize(),
(int)(lena->xsize()*0.75),
(int)(lena->xsize()*0.5),
(int)(lena->xsize()*0.25),
(int)(1),
(int)(lena->xsize()*0.25),
(int)(lena->xsize()*0.5),
(int)(lena->xsize()*0.75)}),int xsize)
{
object o=lena->scale(xsize,lena->ysize());
object p=lena->clear(0,0,0);
p->paste(o,(lena->xsize()-o->xsize())/2,0);
s+=Image.GIF.render_block(p,nct,0,0,0,25);
}
s+=Image.GIF.netscape_loop_block(200);
s+=Image.GIF.end_block();
write(s);
The image.
Colortable with colors to use and to write as palette.
Position of this image.
If set, writes a local palette.
Alpha channel image; black is transparent.
Color of transparent pixels. Not all decoders understands transparency. This is ignored if localpalette isn't set.
View this image for this many centiseconds. Default is zero.
Index of the transparent color in the colortable. -1 indicates no transparency.
If set: wait the delay or until user input. If delay is zero, wait indefinitely for user input. May sound the bell upon decoding. Default is non-set.
Disposal method number;
This is in the advanced sector of the GIF support; please read some about how GIFs are packed.
The user_input and disposal method are unsupported in most decoders.
encode , header_block , end_block
array Image.GIF._decode(string gifdata)
array Image.GIF._decode(array __decoded)
Decodes a GIF image structure down to chunks, and also decode the images in the render chunks.
({int xsize,int ysize, // 0: size of image drawing area
void|object colortable, // 2: opt. global colortable
({ int aspx, int aspy, // 3 0: aspect ratio or 0, 0 if not set
int background }), // 2: index of background color
followed by any number these blocks in any order (gce chunks
are decoded and incorporated in the render chunks):
({ GIF.RENDER, // 0: block identifier
int x, int y, // 1: position of render
object image, // 3: render image
void|object alpha, // 4: 0 or render alpha channel
object colortable, // 5: colortable (may be same as global)
int interlace, // 6: interlace flag
int trans_index, // 7: 0 or transparent color index
int delay, // 8: 0 or delay in centiseconds
int user_input, // 9: user input flag
int disposal}) // 10: disposal method number (0..7)
({ GIF.EXTENSION, // 0: block identifier
int extension, // 1: extension number
string data }) // 2: extension data
and possibly ended with one of these:
({ GIF.ERROR_PREMATURE_EOD }) // premature end-of-data
({ GIF.ERROR_TOO_MUCH_DATA, // data following end marker
string data }) // (rest of file)
({ GIF.ERROR_UNKNOWN_DATA, // unknown data
string data }) // (rest of file)
The decode method uses this data in a way similar to this program:
import Image;
object my_decode_gif(string data)
{
array a=GIF._decode(data);
object img=image(a[0],a[1]);
foreach (a[4..],array b)
if (b[0]==GIF.RENDER)
if (b[4]) img->paste_alpha(b[3],b[4],b[1],b[2]);
else img->paste(b[3],b[1],b[2]);
return img;
}
GIF data (with header and all)
GIF data as from __decode
the above array
May throw errors if the GIF header is incomplete or illegal.
This is in the very advanced sector of the GIF support; please read about how GIF files works.
string Image.GIF._encode(array data)
Encodes GIF data; reverses _decode.
data as returned from _encode
Some given values in the array are ignored. This function does not give the _exact_ data back!
string Image.GIF._gce_block(int transparency, int transparency_index, int delay, int user_input, int disposal)
This function gives back a Graphic Control Extension block. A GCE block has the scope of the following render block.
The following image has transparency, marked with this index.
View the following rendering for this many centiseconds (0..65535).
Wait the delay or until user input. If delay is zero, wait indefinitely for user input. May sound the bell upon decoding.
Disposal method number;
This is in the very advanced sector of the GIF support; please read about how GIF files works.
Most decoders just ignore some or all of these parameters.
_render_block , render_block
string Image.GIF._render_block(int x, int y, int xsize, int ysize, int bpp, string indices, 0|string colortable, int interlace)
Advanced (!) method for writing renderblocks for placement in a GIF file. This method only applies LZW encoding on the indices and makes the correct headers.
Position of this image.
Size of the image. Length if the indices string must be xsize*ysize.
Bits per pixels in the indices. Valid range 1..8.
The image indices as an 8bit indices.
Colortable with colors to write as palette. If this argument is zero, no local colortable is written. Colortable string len must be 1<<bpp.
Interlace index data and set interlace bit. The given string should _not_ be pre-interlaced.
This is in the very advanced sector of the GIF support; please read about how GIF files works.
encode , _encode , header_block , end_block
array Image.GIF.__decode()
Decodes a GIF image structure down to chunks and
({int xsize,int ysize, // 0: size of image drawing area
int numcol, // 2: suggested number of colors
void|string colortable, // 3: opt. global colortable
({ int aspx, int aspy, // 4,0: aspect ratio or 0, 0 if not set
int background }), // 1: index of background color
followed by any number these blocks in any order:
({ GIF.EXTENSION, // 0: block identifier
int extension, // 1: extension number
string data }) // 2: extension data
({ GIF.RENDER, // 0: block identifier
int x, int y, // 1: position of render
int xsize, int ysize, // 3: size of render
int interlace, // 5: interlace flag
void|string colortbl, // 6: opt. local colortable
int lzwsize, // 7: lzw code size
string lzwdata }) // 8: packed lzw data
and possibly ended with one of these:
({ GIF.ERROR_PREMATURE_EOD }) // premature end-of-data
({ GIF.ERROR_TOO_MUCH_DATA, // data following end marker
string data }) // (rest of file)
({ GIF.ERROR_UNKNOWN_DATA, // unknown data
string data }) // (rest of file)
the above array
May throw errors if the GIF header is incomplete or illegal.
This is in the very advanced sector of the GIF support; please read about how GIF files works.
Module Image.JPEG |
This module uses libjpeg, a software from Independent JPEG Group.
string Image.JPEG.encode(object image)
string Image.JPEG.encode(string|object image, mapping options)
Encodes an image object with JPEG compression. The image may also be a string containing a raw JPEG image. In the The options argument may be a mapping containing zero or more encoding options:
|
Please read some about JPEG files. A quality setting of 100 does not mean the result is lossless.
object Image.JPEG.decode(string data)
object Image.JPEG.decode(string data, mapping options)
mapping Image.JPEG._decode(string data)
mapping Image.JPEG._decode(string data, mapping options)
mapping Image.JPEG.decode_header(string data)
Decodes a JPEG image. The simple decode function simply gives the image object, the other functions gives a mapping of information (see below).
The options argument may be a mapping containing zero or more decoding options:
|
_decode and decode_header gives a mapping as result, with this content:
|
mapping(int:array(array(int))) Image.JPEG.quant_tables(int|void a)
Document this function
constant Image.JPEG.IFAST
constant Image.JPEG.FLOAT
constant Image.JPEG.DEFAULT
constant Image.JPEG.ISLOW
constant Image.JPEG.FASTEST
constant Image.JPEG.FLIP_H
constant Image.JPEG.FLIP_V
constant Image.JPEG.ROT_90
constant Image.JPEG.ROT_180
constant Image.JPEG.ROT_270
constant Image.JPEG.TRANSPOSE
constant Image.JPEG.TRANSVERSE
CLASS Image.JPEG.Marker |
constant EOI
constant RST0
constant COM
constant APP0
constant APP1
constant APP2
constant APP3
constant APP4
constant APP5
constant APP6
constant APP7
constant APP8
constant APP9
constant APP10
constant APP11
constant APP12
constant APP13
constant APP14
constant APP15
Module Image.TIFF |
object Image.TIFF.decode(string data)
Decodes a TIFF image.
Throws upon error in data.
mapping(string:mixed) Image.TIFF._decode(string data)
Decodes a TIFF image to a mapping with at least the members image and alpha.
|
Throws upon error in data.
string Image.TIFF.encode(object image)
string Image.TIFF.encode(object image, mapping options)
string Image.TIFF._encode(object image)
string Image.TIFF._encode(object image, mapping options)
Encode an image object into a TIFF file. [encode] and _encode are identical.
The options argument may be a mapping containing zero or more encoding options. See _decode .
Image.TIFF.encode(img, ([ "compression":Image.TIFF.COMPRESSION_LZW, "name":"an image name", "comment":"an image comment", "alpha":An alpha channel, "dpy":Dots per inch (as a float), "xdpy":Horizontal dots per inch (as a float), "ydpy":Vertical dots per inch (as a float), ]));
constant Image.TIFF.COMPRESSION_NONE
constant Image.TIFF.COMPRESSION_CCITTRLE
constant Image.TIFF.COMPRESSION_CCITTFAX3
constant Image.TIFF.COMPRESSION_CCITTFAX4
constant Image.TIFF.COMPRESSION_CCITTRLEW
constant Image.TIFF.COMPRESSION_LZW
constant Image.TIFF.COMPRESSION_JPEG
constant Image.TIFF.COMPRESSION_NEXT
constant Image.TIFF.COMPRESSION_PACKBITS
constant Image.TIFF.COMPRESSION_THUNDERSCAN
Module Image.TTF |
This module adds TTF (Truetype font) capability to the Image module.
This module needs the libttf "Freetype" library
object Image.TTF.`()(string filename)
object Image.TTF.`()(string filename, mapping options)
Makes a new TTF Face object.
The filename of the TTF font or the TTC font collection.
advanced options:
"face":int
If opening a font collection, '.TTC',
this is used to get other fonts than the first.
0 if failed.
CLASS Image.TTF.Face |
This represents instances of TTF Faces.
object flush()
This flushes all cached information. Might be used to save memory - the face information is read back from disk upon need.
the object being called
mapping names()
array(array) _names()
Gives back the names or the complete name-list of this face.
The result from names () is a mapping,
which has any or all of these indices:
"copyright": ("Copyright the Foo Corporation...bla bla")
"family": ("My Little Font")
"style": ("Bold")
"full": ("Foo: My Little Font: 1998")
"expose": ("My Little Font Bold")
"version": ("June 1, 1998; 1.00, ...")
"postscript": ("MyLittleFont-Bold")
"trademark": ("MyLittleFont is a registered...bla bla")
This is extracted from the information from _names(), and fit into pike-strings using unicode or iso-8859-1, if possible.
The result from _names () is a
matrix, on this form:
({ ({ int platform, encoding, language, id, string name }),
({ int platform, encoding, language, id, string name }),
...
})
the name as a mapping to string or the names as a matrix
To use the values from _names (), check the TrueType standard documentation.
mapping properties()
This gives back a structure of the face's properties. Most of this stuff is information you can skip.
The most interesting item to look at may be ->num_Faces, which describes the number of faces in a .TTC font collection.
a mapping of a lot of properties
object `()()
This instantiates the face for normal usage - to convert font data to images.
a Image.TTF.FaceInstance object.
CLASS Image.TTF.FaceInstance |
This is the instance of a face, with geometrics, encodings and stuff.
void Image.TTF.FaceInstance(object face)
creates a new Instance from a face.
Module Image.XFace |
This module uses libgmp.
object Image.XFace.decode(string data)
object Image.XFace.decode(string data, object mappingoptions)
Decodes an X-Face image.
The options argument may be a mapping containing zero options.
object Image.XFace.decode_header(string data)
object Image.XFace.decode_header(string data, object mappingoptions)
Decodes an X-Face image header.
"xsize":int
"ysize":int
size of image
"type":"image/x-xface"
file type information
The options argument may be a mapping containing zero options.
There aint no such thing as a X-Face image header. This stuff tells the characteristics of an X-Face image.
string Image.XFace.encode(object img)
string Image.XFace.encode(object img, object mappingoptions)
Encodes an X-Face image.
The img argument must be an image of the dimensions 48 by 48 pixels. All non-black pixels will be considered white.
The options argument may be a mapping containing zero options.
Module Image.Dims |
Reads the dimensions of images of various image formats without decoding the actual image.
array(int) Image.Dims.get_JPEG(Stdio.File f)
Reads the dimensions from a JPEG file and returns an array with width and height, or if the file isn't a valid image, 0.
array(int) Image.Dims.get_GIF(Stdio.File f)
Reads the dimensions from a GIF file and returns an array with width and height, or if the file isn't a valid image, 0.
array(int) Image.Dims.get_PNG(Stdio.File f)
Reads the dimensions from a PNG file and returns an array with width and height, or if the file isn't a valid image, 0.
array(int) Image.Dims.get(string|Stdio.File file)
Read dimensions from a JPEG, GIF or PNG file and return an array with width and height, or if the file isn't a valid image, 0. The argument file should be either a path to a file or a file object. The offset pointer will be assumed to be at the start of the file and will be modified by the function.
Module Image.Fonts |
Abstracted Font-handling support. Should be used instead of accessing the FreeType, TTF and Image.Font modules directly.
constant Image.Fonts.ITALIC
The font is/should be italic
constant Image.Fonts.BOLD
The font is/should be bold
constant Image.Fonts.NO_FAKE
Used in open_font () to specify that no fake bold or italic should be attempted.
Font Image.Fonts.open_font(string fontname, int size, int flags, int|void force)
Find a suitable font in the directories specified with set_font_dirs .
flags is a bitwise or of 0 or more of ITALIC , BOLD and NO_FAKE .
fontname is the human-readable name of the font.
If force is true, a font is always returned (defaulting to arial or the pike builtin font), even if no suitable font is found.
mapping Image.Fonts.list_fonts()
Returns a list of all the fonts as a mapping.
void Image.Fonts.set_font_dirs(array(string) directories)
Set the directories where fonts can be found.
CLASS Image.Fonts.Font |
The abstract Font class. The file is a valid font-file, size is in pixels, but the size of the characters to be rendered, not the height of the finished image (the image is generally speaking bigger then the size of the characters).
static string file
static int sizevoid Image.Fonts.Font(string file, int size)
int set_fake_bold(int fb)
The amount of 'boldness' that should be added to the font when text is rendered.
int set_fake_italic(int(0..1) fi)
If true, make the font italic.
array(int) text_extents(string ... lines)
Returns ({ xsize, ysize }) of the image that will result if lines is sent as the argument to write .
mapping info()
Returns some information about the font. Always included: file: Filename specified when the font was opened size: Size specified when the font was opened family: Family name style: Bitwise or of the style flags, i.e. ITALIC and BOLD .
Image.Image write(string ... line)
Render the text strings sent as line as an alpha-channel image.
Module Image.DWG |
This module decodes the thumbnail raster images embedded in AutoCAD DWG files for AutoCAD version R13, R14 and R2000 (which equals to file version 12, 14 and 15). Implemented according to specifications from http://www.opendwg.org/.
mapping Image.DWG.__decode(string data)
Decodes the DWG data into a mapping.
|
This functions throws an error when decoding somehow fails.
mapping Image.DWG._decode(string data)
Works like __decode , but in addition it has the element "image" in the result mapping, containing the first successfully decoded bitmap image. to the result of decode(data).
If no preview was stored, or no preview could be decoded an error is thrown.
Image.Image Image.DWG.decode(string data)
Returns the first successfully decoded bitmap image.
If no preview was stored, or no preview could be decoded an error is thrown.
Module Image.PS |
Codec for the Adobe page description language PostScript. Uses Ghostscript for decoding.
object Image.PS.decode(string data, mapping|void options)
Decodes the postscript data into an image object using Ghostscript.
Optional decoding parameters.
|
mapping Image.PS._decode(string data, mapping|void options)
Calls decode and returns the image in the "image" index of the mapping. This method is present for API reasons.
string Image.PS.encode(object img, mapping|void options)
Encodes the image object img as a postscript 3.0 file.
Optional extra encoding parameters.
|
function Image.PS._encode
Same as encode. Present for API reasons.
Module Image.PSD |
mapping Image.PSD.__decode(string|mapping data)
Decodes a PSD image to a mapping, defined as follows.
|
The resources mapping. Unknown resources will be identified by their ID number (as an int).
|
The layer mapping:
|
array(Image.Layer) Image.PSD.decode_layers(string data, mapping|void options)
Decodes a PSD image to an array of Image.Layer objects
Takes the same aptions mapping as _decode , note especially "draw_all_layers":1, but implements "crop_to_bounds" which preserves the bounding box for the whole image (i.e. discards data that extend outside of the global bounds).
The layer object have the following extra variables (to be queried using Image.Layer()->get_misc_value ):
|
mapping Image.PSD._decode(string|mapping data, mapping|void options)
Decodes a PSD image to a mapping, with at least an 'image' and possibly an 'alpha' object. Data is either a PSD image, or a mapping (as received from __decode )
|
|
Throws upon error in data. For more information, see __decode
Image.Image Image.PSD.decode(string data)
Decodes a PSD image to a single image object.
Throws upon error in data. To get access to more information like alpha channels and layer names, see _decode and __decode .