【发布时间】:2018-10-02 13:15:02
【问题描述】:
实际上,在这里用户可以上传任何尺寸的图像以适合我拥有的任何框架。我想在不丢失比例的情况下将该图像放入框架中。
例子:
This image is not fitting with my php code.
我的代码是
list($width, $height) = getimagesize($img1);
$outputImage = imagecreatetruecolor($width, $height);
// set background to white
//$white = imagecolorallocate($outputImage, 255, 255, 255);
//imagefill($outputImage, 0, 0, $white);
list($width1, $height1) = getimagesize($img2);
$info1 = getimagesize($img1);
$info2 = getimagesize($img2);
$extension1 = image_type_to_extension($info1[2]);
$extension2 = image_type_to_extension($info2[2]);
if($extension1=='.jpeg') {
$first = imagecreatefromjpeg($img1);
} else {
$first = imagecreatefrompng($img1);
}
if($extension2=='.jpeg') {
$second = imagecreatefromjpeg($img2);
} else {
$second = imagecreatefrompng($img2);
}
$ratio = $width1 / $height1;
$targetWidth = 300 * $ratio;
//echo $targetWidth;
//imagecopyresized ( 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 )
imagecopyresampled($outputImage,$first,0,0,0,0, $width, $height, $width, $height);
imagecopyresampled($outputImage,$second,110,75,0,0, $targetWidth, 300, $width1, $height1);
请帮助我。提前致谢。
【问题讨论】: