This article mainly introduces the implementation of PHP in the server-side to complete the image size adjustment, interested in the friend's reference, I hope to help you.
This article explains how PHP implements resizing images on the server side. The specific analysis is as follows:
The resizing of the image on the server side is a lot more beneficial than the browser processing.
This article describes how PHP adjusts the image size on the server side.
The code consists of two parts:
①imageresizer () is used to process the image
②loadimage () inserts the image URL in a simpler format
<?php function Imageresizer ($url, $width, $height) {header (' content-type:image/jpeg '); List ($width _orig, $height _orig) = getimagesize ($url); $ratio _orig = $width _orig/$height _orig; if ($width/$height > $ratio _orig) {$width = $height * $ratio _orig; } else {$height = $width/$ratio _orig; }//This resamples the image $image _p = Imagecreatetruecolor ($width, $height); $image = Imagecreatefromjpeg ($url); Imagecopyresampled ($image _p, $image, 0, 0, 0, 0, $width, $height, $width _orig, $height _orig); Output the image imagejpeg ($image _p, NULL, 100); }//works with both POST and GET $method = $_server[' Request_method ']; if ($method = = ' GET ') {imageresize ($_get[' url '), $_get[' W '], $_get[' h ']); } elseif ($method = = ' POST ') {imageresize ($_post[' url '), $_post[' W '], $_post[' h ']); }//makes the process simpler function loadimage ($url, $width, $height) {echo ' image.php?url= ', UrlEncode ($url), ' & ; w= ', $width, ' &h= ', $height; }?>
Usage:
Above code would is in a file called Image.php.//images would is displayed like This:
Summary: The above is the entire content of this article, I hope to be able to help you learn.
Related recommendations:
Get weekly information for a month based on PHP
PHP implements the ability to send and receive text messages
PHP 10 functions for processing sessions