嗨有可能转换图像透视...所以它的新形状是等腰梯形? 我看到了一个解决方案使用ImageMagick,但是这将涉及可能重写我的整个图像处理脚本...(更不用说学习,其中我过敏)PHP GD图像视角
2
A
回答
4
GD不支持3D图像操作:( 的使用ImageMagick溶液并不复杂:http://valokuva.org/?p=112
10
我具有改善的詹姆斯已经发布功能
补充:
- 垂直/水平透视小号upport
- 透明度
- 它看起来更像是在现在的3D旋转物体(接近ojects都较大,而远一些较小)
这里是我的功能:
define("TOP",0);
define("BOTTOM",1);
define("LEFT",2);
define("RIGHT",3);
function perspective($i,$gradient=0.85,$rightdown=TOP,$background=0xFFFFFF, $alpha=0) {
$w=imagesx($i);
$h=imagesy($i);
$col=imagecolorallocatealpha($i,($background>>16)&0xFF,($background>>8)&0xFF,$background&0xFF,$alpha);
$mult=5;
$li=imagecreatetruecolor($w*$mult,$h*$mult);
imagealphablending($li,false);
imagefilledrectangle($li,0,0,$w*$mult,$h*$mult,$col);
imagesavealpha($li,true);
imagecopyresized($li,$i,0,0,0,0,$w*$mult,$h*$mult,$w,$h);
imagedestroy($i);
$w*=$mult;
$h*=$mult;
$image=imagecreatetruecolor($w,$h);
imagealphablending($image,false);
imagefilledrectangle($image,0,0,$w,$h,$col);
imagealphablending($image,true);
imageantialias($image,true);
$test=$h*$gradient;
$rdmod=$rightdown%2;
$min=1;
if($rightdown<2){
for($y=0;$y<$h;$y++){
$ny=$rdmod? $y : $h-$y;
$off=round((1-$gradient)*$w*($ny/$h));
$t=((1-pow(1-pow(($ny/$h),2),0.5))*(1-$gradient)+($ny/$h)*$gradient);
$nt=$rdmod? $t : 1-$t;
if(abs(0.5-$nt)<$min){
$min=abs(0.5-$nt);
$naty=$off;
}
imagecopyresampled($image,$li,
round($off/2),$y,
0,abs($nt*$h),
$w-$off,1,
$w,1);
}
} else {
for($x=0;$x<$w;$x++){
$nx=$rdmod? $x : $w-$x;
$off=round((1-$gradient)*$h*($nx/$w));
$t=((1-pow(1-pow(($nx/$w),2),0.5))*(1-$gradient)+($nx/$w)*$gradient);
$nt=$rdmod? $t : 1-$t;
if(abs(0.5-$nt)<$min){
$min=abs(0.5-$nt);
$natx=$off;
}
imagecopyresampled($image,$li,
$x,round($off/2),
abs($nt*$w),0,
1,$h-$off,
1,$h);
}
}
imagedestroy($li);
imageantialias($image,false);
imagealphablending($image,false);
imagesavealpha($image,true);
$i=imagecreatetruecolor(($w+$naty)/$mult,($h+$natx)/$mult);
imagealphablending($i,false);
imagefilledrectangle($i,0,0,($w+$naty)/$mult,($h+$natx)/$mult,$col);
imagealphablending($i,true);
imageantialias($i,true);
imagecopyresampled($i,$image,0,0,0,0,($w+$naty)/$mult,($h+$natx)/$mult,$w,$h);
imagedestroy($image);
imagealphablending($i,false);
imageantialias($i,false);
imagesavealpha($i,true);
return $i;
}
例子:
Original image: http://imgur.com/iX5Aski
使用功能:
$img=perspective($img,0.5,TOP,0xFFFFFF,127);
结果:
$img=perspective($img,0.2,RIGHT,0xFFFFFF,127);
结果:
+0
This is AWESOME,Thanks @Daniel – 2014-05-14 09:31:47
相关问题
- 1. 用PHP拼接图像GD
- 2. PHP,GD,图像处理
- 3. PHP GD图像不合并
- 4. Php Gd旋转图像
- 5. php gd图像类型
- 6. php GD图像质量差
- 7. php gd图像质量
- 8. PHP的GD - 扭曲图像墨卡托投影视图
- 9. PHP GD图书馆 - 显示图像
- 10. 添加GD图像的另一个GD图像
- 11. html css或php gd库两个图像合并转角到角落
- 12. 亚马逊EC2 - PHP GD图像库
- 13. php GD为图像添加填充
- 14. 在GD中使用php合并图像
- 15. 在GD中使用php合并图像
- 16. PHP GD:透明图像模糊
- 17. GD PHP旋转图像黑色边框
- 18. 将文本放入图像PHP GD
- 19. PHP的GD库图像使用BASE64_ENCODE
- 20. 2个文件的PHP GD图像
- 21. PHP和GD破损的图像
- 22. PHP gd缩小生成图像
- 23. PHP GD图像裁剪功能
- 24. 用PHP嵌入IPTC图像数据GD
- 25. PHP GD - 不透明水印图像
- 26. 在GD(PHP)中找不到图像
- 27. PHP GD库,Symfony中图像的路径
- 28. PHP GD图像 - 输出动画GIF
- 29. 使用GD与PHP合并图像
- 30. 如何使用PHP GD放大图像?
链接死了,但这里的最新缓存: https://web.archive.org/ web/20130424232913/http://valokuva.org/?p = 112 – 2016-04-24 06:01:18