2016-12-18 4 views
1

gd + phpで画像を回転すると枠が表示され、何が間違っているのか分かりません。gd + phpで画像を回転すると枠が表示されます

<?php 
$size = 900; 
$img = imagecreate($size, $size); 

imagesavealpha($img, true); 
$color = imagecolorallocatealpha($img, 0, 0, 0, 127); 
imagefill($img, 0, 0, $color); 

$lines_color = imagecolorallocate($img, 0, 0, 0); 

imageline($img, ($size * 0.50), ($size * 0.00), ($size * 0.50), ($size * 1.00), $lines_color); 
imageline($img, ($size * 0.20), ($size * 0.00), ($size * 0.80), ($size * 1.00), $lines_color); 
imageline($img, ($size * 0.00), ($size * 0.20), ($size * 1.00), ($size * 0.80), $lines_color); 
imageline($img, ($size * 0.00), ($size * 0.50), ($size * 1.00), ($size * 0.50), $lines_color); 
imageline($img, ($size * 0.00), ($size * 0.80), ($size * 1.00), ($size * 0.20), $lines_color); 
imageline($img, ($size * 0.20), ($size * 1.00), ($size * 0.80), ($size * 0.00), $lines_color); 

$img = imagerotate($img, 45, 1); 
imagesavealpha($img, true); 
$color = imagecolorallocatealpha($img, 0, 0, 0, 127); 
imagefill($img, 0, 0, $color); 

header("Content-Type: image/png"); 
imagepng($img, 'demo.png'); 

結果:魔法の境界線が追加さ: -/

Image png result

+0

は、なぜあなたはすべてのあなたの背景に黒使用していますか?それは黒くする必要がありますか?もしそうなら、なぜ透明度をフルに設定していますか(127)?画像を回転させた後、背景をもう一度塗りつぶすのはなぜですか? – EhsanT

答えて

0

imagerotate用透明背景色を渡します

$transparent = imagecolortransparent($img, $color); 
$img = imagerotate($img, 45, $transparent); 
関連する問題