php+imagerotate+png,php – 使用imagerotate()旋转图像后如何获得新的宽度和高度?

标签:php

如何实际获得旋转图像后设置的新宽度和高度?

$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

来源: https://codeday.me/bug/20190528/1171321.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值