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