copy. Copying image fragments

^image.copy[source](x1;y1;width1;height1;x2;y2)
^image.copy[source](x1;y1;width1;height1;x2;y2;width2;height2;color_precision)

The method copies a fragment of one image to another. It is very useful in such tasks as placing signs on a map. The method gets the following parameters:

1.   
Source image
2.   Coordinates (
X1;Y1) of the left top corner of copied fragment
3.   
Width and height of copied fragment
4.   Coordinates (
X2;Y2) to which copied fragment will be pasted
5.   As optional parameters you can specify new width and height of pasted fragment (in this case the fragment will undergo scaling), and    value characterizing precision of color reproduction, The less this value is, the more precise the color reproduction will be, but number of    reproduced colors is decreased in this case-and vice versa (default number of colors is 150)

$mygif[^image::load[test.gif]]

$resample_width($mygif.
width*2)
$resample_height($mygif.height*2)

$mygif_new[^image::
create($resample_width;$resample_height)]
^mygif_new.
copy[$mygif](0;0;20;30;0;0;$mygif_new.width;$mygif_new.height)

$
response:body[^mygif_new.gif[]]

In this example, we create two objects of class
image. The first is based on existing GIF file; the second, which is twice as big, is generated by Parser itself. After that, we copy into it the fragment of the first file scaled up to the entire width and height of the second image. The last line of the code outputs the scaled fragment. It is advisable to use this approach only to the images, which do not demand high quality.


Copyright © 1997–2021 Art. Lebedev Studio | http://www.artlebedev.com Last updated: 20.09.2007