(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)
imagecopyresampled — Copy and resize part of an image with resampling
Description imagecopyresampled( GdImage $dst_image, GdImage $src_image, int $dst_x, int $dst_y, int $src_x, int $src_y, int $dst_width, int $dst_height, int $src_width, int $src_height): boolimagecopyresampled() copies a rectangularportion of one image to another image, smoothly interpolating pixelvalues so that, in particular, reducing the size of an image stillretains a great deal of clarity.
In other words, imagecopyresampled() will take a rectangular area from src_image of width src_width and height src_height at position (src_x,src_y) and place it in a rectangular area of dst_image of width dst_width and height dst_heightat position (dst_x,dst_y).
If the source and destination coordinates and width and heightsdiffer, appropriate stretching or shrinking of the image fragmentwill be performed. The coordinates refer to the upper leftcorner. This function can be used to copy regions within thesame image (if dst_image is the same assrc_image) but if the regions overlap theresults will be unpredictable.
Parameters dst_imageDestination image resource.
src_imageSource image resource.
dst_xx-coordinate of destination point.
dst_yy-coordinate of destination point.
src_xx-coordinate of source point.
src_yy-coordinate of source point.
dst_widthDestination width.
dst_heightDestination height.
src_widthSource width.
src_heightSource height.
Return ValuesReturns true on success or false on failure.
Changelog Version Description 8.0.0 dst_image and src_image expectGdImage instances now; previously, resourceswere expected.ExamplesExample #1 Simple example
This example will resample an image to half its original size.
The above example will outputsomething similar to:
Example #2 Resampling an image proportionally
This example will display an image with the maximum width, or height, of 200 pixels.
The above example will outputsomething similar to:
NotesNote:
There is a problem due to palette image limitations (255+1 colors).Resampling or filtering an image commonly needs more colors than 255, akind of approximation is used to calculate the new resampled pixel and itscolor. With a palette image we try to allocate a new color, if thatfailed, we choose the closest (in theory) computed color. This isnot always the closest visual color. That may produce a weird result, likeblank (or visually blank) images. To skip this problem, please use atruecolor image as a destination image, such as one created byimagecreatetruecolor().
See Also imagecopyresized() - Copy and resize part of an imageimagescale() - Scale an image using the given new width and heightimagecrop() - Crop an image to the given rectangle