 2008/08/30
|
Last update 2001/05/16
The Labs - Design & Functionality For The Net
PicArt Cookbook
This page will illustrate some common effects, tricks and
strategies to use PicArt-page and its
PicArt-Script.
- Writing Stand-alone Scripts
- Sample Script
- inside-border
- Sample Script
- fancy
- ProgrammerHTML & PicArt
- Metal Letters
- On The Fly
- Resources
| PicArt Cookbook1. Writing Stand-alone Scripts
|
First of all, how to write standalone scripts:
|
#!/usr/local/bin/pascript-wrapper
|
pascript-wrapper is a wrapper to call pascript properly.
All command-line arguments will be pushed on the stack. Remember, all
is stack oriented so they get them in the reversed order:
|
% ./test.pa "hello" a.jpg
|
The possible source might be:
|
#!/usr/local/bin/pascript-wrapper
|
|
|
|
printstack # display the stack to see
|
|
xv # display 2nd argument (the picture)
|
|
print # print out 1st argument (last on the stack)
|
If the order of the arguments gets to complicate to write code
so assign the args to some variables:
|
/pic exch def
|
|
/string exch def
|
or
both ways do exactly the same. Some programmers who know PostScript
may feel more comfortable with exch def, those more coming
from C or general procedural languages may prefere = ;
way.
Also, the script does nothing unless you write it, the PicArt Script
don't give anything out, ie. text or images, you must declare the
writing of the image by yourself like:
|
... tojpeg(85,"my.jpeg");
|
|
... togif(255,"my.gif");
|
|
... toppm("my.ppm");
|
The ... indicate you created an image within the source already,
three formats are supported, JPEG, GIF and PPM.
Again, since there are so many commands and its arguments, call
to get some info of it.
| PicArt Cookbook2. Sample Script: inside-border
|
|
#!/usr/local/bin/pascript-wrapper
|
|
|
|
"inside-border: [<filename>] <image>" 1 expect
|
|
|
|
/pic exch def
|
|
pic sizeof /h exch def /w exch def
|
|
|
|
w 10 add h 10 add 5 100 100 100 button
|
|
invert
|
|
.8 .8 .8 1. gamma
|
|
5 5 pic paste
|
|
|
|
stackdepth 2 lt
|
|
{ xv }
|
|
{ exch 75 exch tojpeg }
|
|
ifelse
|
Before I comment each line, let me say that this source code is
written the 'stack' oriented way unlike the next example below "fancy".
- The expect command is prompts when the script doesn't get
at least 1 argument.
- /pic exch makes the assigment
- pic sizeof gives size of the picture
- then add the args before button define the button,
then invert make it go inside looking
- gamma makes it a bit darker
- then we paste to original pic into it
- finally we check if the script was called with 1 or 2 command-line
arguments, either create a JPEG or call xv to display it.
Usage:
|
% ./inside-border SampleImages/albuquerque.jpg
|
| PicArt Cookbook3. Sample Script: fancy
|
|
#!/usr/local/bin/pascript-wrapper
|
|
|
|
"fancy: <font> <size> <text>" 3 expect
|
|
|
|
/itxt = ; # assign last arg <text>
|
|
setfontsize(); # set fontsize
|
|
setfont(); # set font family
|
|
|
|
setrgb(0,80,0); # color dark green
|
|
/pic = border(show(itxt), 10,10,0,0,0,255)
|
|
# show create bitmap
|
|
# and put transparent border
|
|
# arround, required for smooth
|
|
|
|
smooth gamma(1,1,1,.1) # smooth and put alpha gamma low
|
|
# (easy way to make bold)
|
|
;
|
|
|
|
pic sizeof /h = ; /w = ;
|
|
/pic1 = pic smooth gamma(1,1,1,.1)
|
|
map(255,255,0,0); # recolor yellow
|
|
/pic2 = pic1 smooth(3) gamma(1,1,1,.01)
|
|
map(200,0,0,0); # recolor red
|
|
|
|
pic # use it as base
|
|
paste(0,0,pic2); # paste red
|
|
paste(0,0,pic1); # paste yellow
|
|
paste(0,0,pic); # and top-layer once again
|
|
|
|
xv # display it
|
As you see, this source code is written in style of function-calls,
and the arguments are enclosed in () instead leading before the call.
Near /pic2 assigment there is a mix of it, sequential
pipeing through several smooth and finally a gamma
adjustment, before maping a new color to it and the
assignment ends with <;>. Again, <;>
is ignored at the end of the function ie. paste(0,0,pic2);,
I just wrote it for likeness of writing C or Perl.
Use the script like:
|
./fancy 'Times-Bold' 40 'Hello'
|
| PicArt Cookbook4. ProgrammerHTML & PicArt
|
ProgrammerHTML is an extension of HTML
which you are able to define new tags. Using this feature,
as described in ProgrammerHTML Cookbook
already, you can use following tag-definition:
|
<def name=pascript plugin=inline language=perl>
|
|
`mkdir phtml-pics` if(!(-d "phtml-pics"));
|
|
$arg{type} = 'jpeg' if(!$arg{type});
|
|
$arg{cols} = '240' if(!$arg{cols});
|
|
$options .= "align=$arg{align} " if($arg{align});
|
|
$options .= "hspace=$arg{hspace} " if($arg{hspace});
|
|
$options .= "vspace=$arg{vspace} " if($arg{vspace});
|
|
$options .= "border=$arg{border} " if($arg{border} ne '');
|
|
$rpath = $ENV{REVERSE_PATH};
|
|
$base = $ENV{SOURCE_FILENAME}; $base =~ s/\.phtml//; $base =~ s/\//_/g;
|
|
$fname = "phtml-pics/pascript-inline-$base-$ENV{'PLUGIN_CALLS'}";
|
|
while(<STDIN>) {
|
|
$buff .= $_;
|
|
}
|
|
$fname .= '.jpg', $buff .= " tojpeg(85,$fname);" if($arg{type} eq 'jpeg');
|
|
$fname .= '.gif', $buff .= " togif($arg{transp} $arg{cols},$fname);"
|
|
if($arg{type} eq 'gif');
|
|
`pascript -direct '$buff'`;
|
|
print "<img src=\"$rpath/$fname\" $options>";
|
|
</def>
|
To use the plugin, write the PicArt-Script code:
|
<pascript type=gif transp=0,0,0>
|
|
text.font(/Bajoran); text.size(50);
|
|
/img = border(text("STAR TREK"),2,2,0,0,0,255);
|
|
make(sizeof(img),0,0,0,0);
|
|
paste(0,0,map(img smooth(2) gamma(2,2,2,.2),255,0,0,0));
|
|
paste(0,0,map(img,blend(img,0,.5,0,1, linear, 250,250,0,0, 200,0,0,0)));
|
|
</pascript>
|
| PicArt Cookbook5. Metal Letters
|
In this case study a metal shader is implemented without any
image-tile. First of all, we define how many colors we need to
define a shade, for simplicity we just use two colors.
|
<pascript type=gif transp=0,0,0>
|
|
/col1 = {80 80 120 0};
|
|
/col2 = {245 245 255 0};
|
|
text.font(Times-Bold); text.size(50); text("Metal Letters");
|
|
/t = border(5,5,0,0,0,255);
|
|
make(sizeof(t),0,0,0,0);
|
|
/t0 = map(t,blend(t,0,.4,0,.8,bilinear,
|
|
col1 execstack,col2 execstack)
|
|
wavy.noise(1,.8) wavy(3,80));
|
|
paste(-2,-2,t0); paste(-1,-1,t0);
|
|
paste(1,1,t0); paste(2,2,t0);
|
|
paste(0,0,map(t,blend(t,0,.2,0,.8,bilinear,
|
|
col1 execstack,col2 execstack) ));
|
|
</pascript>
|
Hint: the execstack is used to expand the { } rgba colors.
You may play with the wavy arguments to achieve smoother
effects.
| PicArt Cookbook6. On The Fly
|
Often you need to draw exact things, which are cumbersome to start
any drawing tools (like xpaint or GIMP), you can also use pascript
for this:
|
% pascript -direct "background-html.jpg for(0,246,4,{ /i exch def \
|
|
draw.rgba(0,0,80,120) draw.line(0,i,1200,i);}); cut(0,0,1200,232); \
|
|
draw xv"
|
This will draw 58 horizontal lines unto a picture with vertical
space of 4 pixels, which is this very background of this page.
xv is used to display whereas it is manually stores as GIF.
| PicArt Cookbook7. Resources
|

Last update 2001/05/16 
All Rights Reserved - (C) 1997 - 2008 by The Labs.Com |