Php image processing function imagecopyresampled Usage Details, conditional function if Usage Details
This article describes the usage of the php image processing function imagecopyresampled. We will share this with you for your reference. The details are as follows:
Syntax
Copy codeThe Code is as follows: bool imagecopyresampled (resource $ dst_image, resource $ src_image, int $ dst_x, int $ dst_y, int $ src_x, int $ src_y, int $ dst_w, int $ dst_h, int $ src_w, int $ src_h)
Parameters
Dst_image |
Target Image connection resource. |
Src_image |
Source image connection resource. |
Dst_x |
Target X coordinate point. |
Dst_y |
Target Y coordinate point. |
Src_x |
The X coordinate point of the source. |
Src_y |
Y coordinate point of the source. |
Dst_w |
Target width. |
Dst_h |
Target Height. |
Src_w |
The width of the source image. |
Src_h |
The height of the source image. |
Returns TRUE if the call succeeds, or FALSE if the call fails.
Case
Case (image cutting ):
<? Php $ targ_w = $ targ_h = 150; // set the target width and height to $ pai_quality = 90; // the image quality is 90, the full score is 100 $ src = 'demo _ files/pool.jpg '; // The processed image $ img_r = imagecreatefromjpeg ($ src ); // obtain the source image $ dst_r = ImageCreateTrueColor ($ targ_w, $ targ_h); // obtain the new image imagecopyresampled ($ dst_r, $ img_r, $ _ POST ['X'], $ _ POST ['y'], $ targ_w, $ targ_h, $ _ POST ['W'], $ _ POST ['H']); // target graph source graph target X coordinate point target Y coordinate point source X coordinate point source Y coordinate point target width Target Height source graph width source graph height header ('content-t Ype: image/jpeg '); imagejpeg ($ dst_r, null, $ jpeg_quality); // output the image to a browser or file?>
Case 2 (re-sampling ):
<? Php // source file $ filename = '1.jpg '; // set the maximum width and height $ width = 400; $ height = 400; // Content typeheader ('content-Type: image/jpeg '); // obtain the new size list ($ width_orig, $ height_orig) = getimagesize ($ filename); $ ratio_orig = $ width_orig/$ height_orig; if ($ width/$ height> $ ratio_orig) {$ width = $ height * $ ratio_orig;} else {$ height = $ width/$ ratio_orig ;} // re-sample $ image_p = imagecreatetruecolor ($ width, $ height); $ image = imagecreatef Romjpeg ($ filename); imagecopyresampled ($ image_p, $ image, 0, 0, 0, 0, $ width, $ height, $ width_orig, $ height_orig ); // output imagejpeg ($ image_p, null, 100);?>
Attach three ideas for uploading images
1. Select an image, submit a form, and the server processes the upload and save paths in a unified manner.
2. Select the image, upload, obtain the path, submit the form, and save the path.
3. Select an image, upload it to the server, obtain the image from the server in a certain way, and save it to the local device.