Home > Backend Development > PHP Tutorial > Two PHP pictures proportional scaling_PHP tutorial

Two PHP pictures proportional scaling_PHP tutorial

WBOY
Release: 2016-07-13 10:45:31
Original
1006 people have browsed it

PHP image proportional scaling code is a picture that specifies the proportion of the image based on the image uploaded by the user. The principle is very simple, just calculate the image size and scale it into equal proportions. The second method of generating small images is to fix the image size, but how If the picture is smaller than the set picture, fill it with white. This is a good method.

PHP tutorial picture equal proportion scaling code is a picture that specifies the proportion of the picture based on the picture uploaded by the user. The principle is very simple, just calculate the picture size and scale it into equal proportions. The second method of generating small pictures is to fix the picture size, but How to fill in the blank if the picture is smaller than the set picture? This is a good method.

header("content-type:image/jpeg");
$filename = hsdir.'/mljntc2p.jpg';
$im = imagecreatefromjpeg($filename);
$h=imagesy($im);//Get the target image height
$new_img_width = 257;
$new_img_height = 522;

$newim = imagecreate($new_img_width, $new_img_height);
$white = imagecolorallocate($newim, 255,255,255); //Set the background color
imagecopyresized($newim, $im, 0, 0, 0, 0, $new_img_width, $new_img_height, $new_img_width, $new_img_height);
imagefilledrectangle($newim,0,$h,$new_img_width,$new_img_height,$white);
//Fill the height of the target image as the starting y coordinate and the specified intercepted width and height as the ending coordinate
imagejpeg($newim);
imagedestroy($newim);
imagedestroy($im);
?>

Code 2

header("content-type:image/jpeg");
$filename = 'myface.jpg';
$im = imagecreatefromjpeg($filename);
$new_img_width = 80;
$new_img_height = 150;
$newim = imagecreate($new_img_width, $new_img_height);
$white = imagecolorallocate($newim, 255,255,255); //Set the background color
imagecopyresized($newim, $im, 0, 0, 0, 0, $new_img_width, $new_img_height, $new_img_width, $new_img_height);
imagejpeg($newim);
imagedestroy($newim);
imagedestroy($im);
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/633018.htmlTechArticlephp image proportional scaling code is an image scaling code that specifies the proportion of images based on the images uploaded by the user. The principle is very simple Just calculate the size of the picture and make it proportional. The second method generates a small picture...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template