Php imagecopyresized instance

Source: Internet
Author: User

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 );
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.