object copy( [int x1,int y1,int x2,int y2 [,int r,int g,int b] ] );
object autocrop( [int border_width [,int left,int right,int top,int bottom] [,int r,int g,int b] ] );
object gray();
object color(int r,int g,int b);
object invert();
object mirrorx(void);
object mirrory(void);
object rotate_cw(void);
object rotate_ccw(void);
object threshold([int r,int g,int b]);
object apply_matrix(array(array(int)) matrix,[int r,int g,int b[,int div]]);
object scale(float factor);
object scale(float factorx,float factory);
object scale(int newx|0,int newy|0);
Methods operating on current object:
string toppm(void);
string|object fromppm(string s);
string togif( [int r,inr g,int b] );
object paste(object img [,int x,int y])
object paste_alpha(object img, int alpha [,int x, int y]);
object paste_mask(object img, object alpha_mask [,int x,int y]);
object setcolor(int r,int g,int b);
object setpixel(int x,int y [,int r,int g,int b] );
object line(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] );
object circle(int x,int y,int radx,int rady [,int r,int b,int g] );
object tuned_box(int x1,int y1,int x2,int y2,array(array(int)) corner_rgb);
Information giving methods:
object xsize();
object ysize();
It is possible to use a matrix of RGB groups (ie an array of three integers) instead of the simple values, this making it possible to apply different matrices on red, green and blue channel.
blurred=image->apply_matrix( ({ ({1,2,1}), ({2,3,2}), ({1,2,1}) }) );
A 'Emboss' operation (3x3):
emossed=image->apply_matrix(({ ({0,1,8}), ({-1,0,1}), ({-8,-1,0}) }), 128,128,128, 15 );
Here i'm using 128,128,128 (gray) as a mean, because i get negative values.
The left, right, ... arguments is used to tell which edges should be autocropped.
cropped=image->autocrop();
cyan=image->color(64,255,192);This function is most usable on a image that has been grayed first.
copy=image->copy(); copy=image->copy(-10,-10,image->xsize()+9,image->ysize()+9);
image=clone( (program)"precompiled/image" );
image->fromppm(read_bytes("my_image.ppm",0,10000000));
gray=image->gray()
inverted=image->invert()
image->line(17,100,42,1000);
mirrored=image->mirrorx();
snurr=image->rotate_cw();
image->paste(other_smaller_image,17,42); image->paste_mask(other_image,alpha_channel_image);Paste a dog on a landscape:
landscape->paste(dog,dog_alpha_channel,xpos,ypos);Write some text:
text=font->write("some text");
foreground=text->clear(255,255,255); // white
background->paste(foreground,text,xpos,ypos);
image->tuned_box(0,0,img->xsize()-1,img->ysize()-1,
({({0,0,64}),({16,16,128}),
({16,16,128}),({192,160,128})}));
int main()
{
object txt,o,shad,font;
int i;
txt =
(font=clone((program)"/precompiled/font"))
->load("/usr/local/lib/pike/fonts/64/helvetica_bold_r")
->write("The Image Module")
->autocrop(20,0,0,0);
shad=txt->mirrory()->scale(1.0,0.3)->color(64,64,64);
o=clone((program)"/precompiled/image",
txt->xsize(),txt->ysize(), 0,0,100)
->tuned_box(0,0,txt->xsize(),txt->ysize(),
({({0,0,0}),({0,0,0}),
({0,0,255}),({128,128,0})}));
o->setcolor(255,255,255,200);
for (i=0; i<30; i++)
if (random(2))
o->line(random(o->xsize()),o->ysize()-10-random(20+i*3),
o->xsize()-1-random(30),o->ysize()-1);
else
o->line(random(o->xsize()),o->ysize()-10-random(20+i),
random(30),o->ysize()-1);
for (i=0; i<10; i++)
o->box(random(o->xsize()),random(o->ysize()),
random(o->xsize()),random(o->ysize()),
random(256),random(256),random(256),220);
o -> paste_mask(txt->clear(0,255,0),
shad,0,(int)(font->baseline()*0.7)+shad->ysize()-10)
-> paste_mask(txt->clear(255,255,0),
txt->apply_matrix(({({1,2,1}),({2,4,2}),({1,2,1})}))
->apply_matrix(({({1,2,1}),({2,4,2}),({1,2,1})}))
->modify_by_intensity(1,0,0, 0,255,255,255,255,255))
-> paste_mask(txt->clone()
->tuned_box(0,0,txt->xsize()-1,txt->ysize()-1,
({({128,128,128}),({64,128,0}),
({64,128,0}),({255,255,0})})),
txt);
write(o->togif_fs());
return 0;
}
object image->select_from(int x,int y);
object image->distancesq(int r,int g,int b);
array(int) image->getpixel(int x,int y);
object image->skewx(int diff,rgb);
object image->skewy(int diff,rgb);
object image->skewx_expand(int diff,rgb);
object image->skewy_expand(int diff,rgb);
object image->rotate(int|float angle,rgb);
object image->rotate_expand(int|float angle,rgb);
object image->turbulence(colorrange,int octaves=3,float scale=1,
float xdiff=0,float ydiff=0,float cscale=1);
object image->noise(colorrange,float scale=0.1,
float xdiff=0,float ydiff=0,float cscale=1);
where colorrange is ({ float position=0..1, ({r,g,b}),
float position=0..1, ({r,g,b}), ... })