gpt4 book ai didi

php - 如何在使用 imagerotate() 旋转图像后获得新的宽度和高度?

转载 作者:可可西里 更新时间:2023-10-31 22:42:34 27 4
gpt4 key购买 nike

我如何真正获得图像旋转后设置的新宽度和高度?

$ps['product_angle'] = 77; //Could be any angle
$filename = 'test.png' //filename to the original product

list($source_width, $source_height) = getimagesize($filename);
$source_image = imagecreatefromjpeg($filename);
$angle = $ps['product_angle'];
if (intval($angle) <> 0) {
$source_image = imagerotate($source_image, 360-$angle, imageColorAllocateAlpha($source_image, 255, 255, 255, 127));
}

$ps['source_image'] = $source_image;

我想要这个是因为我想根据上面创建的图像调整图像大小。 ($ps['source_image'])

//If I do an image 
list($source_width, $source_height) = getimagesize($filename);

$dest_width = (int)$ps['product_width'];
$dest_height = (int)$ps['product_height'];

//Resize source-image to new width and height
//But this width and height are incorrect because they are
//set before image is rotated and often the image is just "cut off"
//
imagecopyresized($dest_image, $ps['source_image'], 0, 0, 0, 0, $dest_width, $dest_height, $source_width, $source_height);

最佳答案

使用函数 imagesx()imagesy()使用 GD 获取在内存中加载或创建的图像的宽度和高度。

$filepath = '/tmp/1.jpg';
$size = getimagesize($filepath);
echo('Image dimensions returned by getimagesize() : '.$size[0].'x'.$size[1]." pixels\n");

$img = imagecreatefromjpeg($filepath);
$width = imagesx($img);
$height = imagesy($img);
echo('Dimensions returned by imagesx() and imagesy(): '.$width.'x'.$height." pixels.\n");

$angle = 60;
$dst = imagerotate($src, $angle, imageColorAllocateAlpha($src, 255, 255, 255, 127));
$width = imagesx($dst);
$height = imagesy($dst);
echo('Dimensions of the rotated image: '.$width.'x'.$height." pixels.\n");

关于php - 如何在使用 imagerotate() 旋转图像后获得新的宽度和高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28762132/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com