Php imagecopyresized instance
Description
Boolean imagecopyresized ($ dst_image, $ src_image, $ dst_x, $ dst_y, $ src_x, $
Src_y, $ dst_w, $ dst_h, $ src_w, $ src_h)
Imagecopyresized () copies the partial image of a rectangle to another image. Dst_image target image
Image, src_image is the identifier of the source image.
In other words, imagecopyresized () is located at the src_w width and height src_h src_image
(Src_x, src_y), and place it in the dst_w width and height dst_h dst_image rectangular area, which is
In the rectangular area of the position (dst_x, dst_y ).
If the source and target coordinates, width, and height are different, appropriate stretching or shrinking image fragments will be performed. Coordinates refer
In the upper left corner. This function can be used to copy images in the same region (for example, dst_image is the same src_image ),
However, the results of overlapping areas are unpredictable.
Parameter description:
Dst_im
Resource of the target image link.
Src_im
SOURCE image link resource.
Dst_x
X coordinate of the destination.
Dst_y
Y coordinate destination.
Src_x
X coordinate.
Src_y
Y coordinate source point.
Dst_w
Destination width.
Dst_h
Target height.
Src_w
SOURCE width.
Src_h
SOURCE height.
Let's take a look at the imagecopyresized function instance.
<? Php
// File and new size
$ Filename = 'test.jpg ';
$ Percent = 0.5;
// Content type
Header ('content-type: image/jpeg ');
// Get new sizes
List ($ width, $ height) = getimagesize ($ filename );
$ Newwidth = $ width * $ percent;
$ Newheight = $ height * $ percent;
// Load
$ Thumb = imagecreatetruecolor ($ newwidth, $ newheight );
$ Source = imagecreatefromjpeg ($ filename );
// Resize
Imagecopyresized ($ thumb, $ source, 0, 0, 0, 0, $ newwidth, $ newheight, $ width,
$ Height );
// Output
Imagejpeg ($ thumb );
?>