contents   index   previous   next

GD copy()


gd.copy(source, dstX, dstY, srcX, srcY, width,


gd.copy(source, dstPoint, srcPoint, width,



source - A gd object to copy from


dstX - Horizontal destination pixel in current object


dstY - Vertical destination pixel in current object


dstPoint - Destination pixel in current object.


srcX - Horizontal source pixel in source object


srcY - Vertical source pixel in source object


srcPoint - Source pixel in source object.


width - Width of section to copy


height - Height of section to copy






This method copies a section from one GD image to another. The portion of source, starting at the specified point (which is the upper-left corner of the region) and extending width and height in either direction. This region is then copied to the current GD object at the specified location (which is again the upper-left corner of the region). In copying the region, this method attempts to preserve the colors of the original source as best as possible. The method first tries calling colorExact() on the current image, and if that doesn't work then colorAllocate(), and finally if that fails, then colorClosest(). If you specify the same source image as the current image, then the method will work appropriately as long as the regions to not overlap. If they do, then the result is undefined.



#link <gd>, GD copyResized()



// Copy top-left 16x16 from "test.gif"

// while attempting to preserve

// necessary colors.

var source = GD.fromGif("test.gif");

var dest = new GD( 16, 16 );

dest.copy( source, [0,0], [0,0], 16, 16 );


GD copyResized()