嗨有可能轉換圖像透視...所以它的新形狀是等腰梯形? 我看到了一個解決方案使用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