Table of Contents
Copying Only
imagecopy()
Copying and Merging
imagecopymerge()
imagecopymergegray()
Copying and Resizing
imagecopyresized()
imagecopyresampled()
This chapter lets you know how to copy images [2][http://
pterodactyl.l2p.net/book/php5image/page/bi01.html#php_manual].
Copying Only
imagecopy()
The imagecopy() function copies part of an image.
bool imagecopy() ( dst_im,
src_im,
dst_x,
dst_y,
src_x,
src_y,
src_w,
src_h);
resource dst_im;
resource src_im;
int dst_x;
int dst_y;
int src_x;
int src_y;
int src_w;
int src_h;
dst_im. An image identifier representing a destination image
src_im. An image identifier representing a source image
dst_x. The x coordinate of an destination image.
dst_y. The y coordinate of an destination image.
src_x. The x coordinate of an source image.
src_y. The y coordinate of an source image.
src_w. The width of a source part.
src_h. The height of a source part.
Return Values. Returns true on success or false on failure.
This function copies a part of src_im onto dst_im starting at the
src_x,src_y coordinates with a width of src_w and a height of src_h.
The portion defined will be copied onto the dst_x,dst_y coordinates.
Copying and Merging
imagecopymerge()
The imagecopymerge() function copies and merges part of an image.
bool imagecopymerge() ( dst_im,
src_im,
dst_x,
dst_y,
src_x,
src_y,
src_w,
src_h,
pct);
resource dst_im;
resource src_im;
int dst_x;
int dst_y;
int src_x;
int src_y;
int src_w;
int src_h;
int pct;
dst_im. An image identifier representing a destination image
src_im. An image identifier representing a source image
dst_x. The x coordinate of an destination image.
dst_y. The y coordinate of an destination image.
src_x. The x coordinate of an source image.
src_y. The y coordinate of an source image.
src_w. The width of a source part.
src_h. The height of a source part.
pct. Alpha transparency.
Return Values. Returns true on success or false on failure.
This function copies a part of src_im onto dst_im starting at the
src_x,src_y coordinates with a width of src_w and a height of src_h.
The portion defined will be copied onto the dst_x,dst_y coordinates.
The two images will be merged according to pct which can range from 0
to 100. When pct = 0, no action is taken, when 100 this function
behaves identically to imagecopy() for pallete images, while it
implements alpha transparency for true colour images.
imagecopymergegray()
The imagecopymergegray() function copies and merges part of an image
with gray scale.
bool imagecopymerge() ( dst_im,
src_im,
dst_x,
dst_y,
src_x,
src_y,
src_w,
src_h,
pct);
resource dst_im;
resource src_im;
int dst_x;
int dst_y;
int src_x;
int src_y;
int src_w;
int src_h;
int pct;
dst_im. An image identifier representing a destination image
src_im. An image identifier representing a source image
dst_x. The x coordinate of an destination image.
dst_y. The y coordinate of an destination image.
src_x. The x coordinate of an source image.
src_y. The y coordinate of an source image.
src_w. The width of a source part.
src_h. The height of a source part.
pct. Alpha transparency.
Return Values. Returns true on success or false on failure.
This finction copies a part of src_im onto dst_im starting at the
src_x,src_y coordinates with a width of src_w and a height of src_h.
The portion defined will be copied onto the dst_x,dst_y coordinates.
The two images will be merged according to pct which can range from 0
to 100. When pct = 0, no action is taken, when 100 this function
behaves identically to imagecopy().
This function is identical to imagecopymerge() except that when
merging it preserves the hue of the source by converting the
destination pixels to gray scale before the copy operation.
Copying and Resizing
imagecopyresized()
The imagecopyresized() function copies and resizes part of an image.
bool imagecopyresized() ( dst_im,
src_im,
dst_x,
dst_y,
src_x,
src_y,
dst_w,
dst_h,
src_w,
src_h);
resource dst_im;
resource src_im;
int dst_x;
int dst_y;
int src_x;
int src_y;
int dst_w;
int dst_h;
int src_w;
int src_h;
dst_im. An image identifier representing a destination image
src_im. An image identifier representing a source image
dst_x. The x coordinate of an destination image.
dst_y. The y coordinate of an destination image.
src_x. The x coordinate of an source image.
src_y. The y coordinate of an source image.
dst_w. The width of a source part.
dst_h. The height of a source part.
src_w. The width of a source part.
src_h. The height of a source part.
Return Values. Returns true on success or false on failure.
This function copies a rectangular portion of one image to another
image.
dst_image is the destination image, src_image is the source image
identifier. If the source and destination coordinates and width and
heights differ, appropriate stretching or shrinking of the image
fragment will be performed. The coordinates refer to the upper left
corner. This function can be used to copy regions within the same
image (if dst_image is the same as src_image) but if the regions
overlap the results will be unpredictable.
[Note][http://pterodactyl.l2p.net/images/docbook/note.png] Note
There is a problem due to palette image limitations (255+1 colors).
Resampling or filtering an image commonly needs more colors than 255,
a kind of approximation is used to calculate the new resampled pixel
and its color. With a palette image we try to allocate a new color, if
that failed, we choose the closest (in theory) computed color. This is
not always the closest visual color. That may produce a weird result,
like blank (or visually blank) images. To skip this problem, please
use a truecolor image as a destination image, such as one created by
imagecreatetruecolor().
[Tip][http://pterodactyl.l2p.net/images/docbook/tip.png] Tip
Better quality can be obtained using imagecopyresampled().
imagecopyresampled()
The imagecopyresampled() function copies and resizes part of an image
with resampling.
bool imagecopyresampled() ( dst_im,
src_im,
dst_x,
dst_y,
src_x,
src_y,
dst_w,
dst_h,
src_w,
src_h);
resource dst_im;
resource src_im;
int dst_x;
int dst_y;
int src_x;
int src_y;
int dst_w;
int dst_h;
int src_w;
int src_h;
dst_im. An image identifier representing a destination image
src_im. An image identifier representing a source image
dst_x. The x coordinate of an destination image.
dst_y. The y coordinate of an destination image.
src_x. The x coordinate of an source image.
src_y. The y coordinate of an source image.
dst_w. The width of a source part.
dst_h. The height of a source part.
src_w. The width of a source part.
src_h. The height of a source part.
Return Values. Returns true on success or false on failure.
This function copies a rectangular portion of one image to another
image, smoothly interpolating pixel values so that, in particular,
reducing the size of an image still retains a great deal of clarity.
dst_image is the destination image, src_image is the source image
identifier. If the source and destination coordinates and width and
heights differ, appropriate stretching or shrinking of the image
fragment will be performed. The coordinates refer to the upper left
corner. This function can be used to copy regions within the same
image (if dst_image is the same as src_image) but if the regions
overlap the results will be unpredictable.
[Note][http://pterodactyl.l2p.net/images/docbook/note.png] Note
There is a problem due to palette image limitations (255+1 colors).
Resampling or filtering an image commonly needs more colors than 255,
a kind of approximation is used to calculate the new resampled pixel
and its color. With a palette image we try to allocate a new color, if
that failed, we choose the closest (in theory) computed color. This is
not always the closest visual color. That may produce a weird result,
like blank (or visually blank) images. To skip this problem, please
use a truecolor image as a destination image, such as one created by
imagecreatetruecolor().
[Warning][http://pterodactyl.l2p.net/images/docbook/warning.png]
Warning
This function requires GD 2.0.1 or later (2.0.28 or later is
recommended).