旋转图像时,我得到了不需要的黑色虚线边框。我试图删除它,但我没有找到任何成功。我使用以下函数进行图像旋转。我试图保持透明度。我也提供了一张图片。
Here is an Image URL: http://s23.postimg.org/hep2pkol7/border.png
function imageRotation ($source, $rotang)
{
imagealphablending($source, false);
imagesavealpha($source, true);
$rotation = imagerotate($source, $rotang, imageColorAllocateAlpha($source, 0, 0, 0, 127));
imagealphablending($rotation, false);
imagesavealpha($rotation, true);
return $rotation;
}
我把这个函数称为:
$rotatedImage = imageRotation($image, 10);
这是完整的代码
<?php
// Some settings
$text = "Previously blogging";
$fontFace = 'Days.ttf';
$fontSize = 90;
$angle = 0;
$bbox = calculateTextBox($text, $fontFace, $fontSize, $angle);
$image = imagecreatetruecolor($bbox['width'], $bbox['height']);
// Define some colors
$black = imagecolorallocate($image, 0, 0, 0);
$yellow = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
//Fill the image with background color
imagefill($image, 0, 0, $yellow);
// Draw text
imagettftext($image, $fontSize, $angle, $bbox['left'], $bbox['top'], $black, $fontFace, $text);
$image = imageRotation($image, 20);
$im = imagecreatefromjpeg('weight-loss.jpg');
// Switch antialiasing on for one image
imageantialias($im, true);
$destWidth = imagesx($im);
$destHeight = imagesy($im);
$src_w = imagesx($image);
$src_h = imagesy($image);
$dst_x = ($destWidth - $src_w)/2;
$dst_y = ($destHeight - $src_h)/2;
imagecopy($im, $image, $dst_x, $dst_y, 0, 0, $src_w, $src_h);
header ('Content-Type: image/jpeg');
imagejpeg($im, null, 100);
imagedestroy($im);
imagedestroy($image);
function calculateTextBox($text,$fontFile,$fontSize,$fontAngle)
{
$rect = imagettfbbox($fontSize,$fontAngle,$fontFile,$text);
$minX = min(array($rect[0],$rect[2],$rect[4],$rect[6]));
$maxX = max(array($rect[0],$rect[2],$rect[4],$rect[6]));
$minY = min(array($rect[1],$rect[3],$rect[5],$rect[7]));
$maxY = max(array($rect[1],$rect[3],$rect[5],$rect[7]));
return array(
"left" => abs($minX),
"top" => abs($minY),
"width" => $maxX - $minX,
"height" => $maxY - $minY,
"box" => $rect
);
}
function imageRotation ($source, $rotang)
{
imagealphablending($source, false);
imagesavealpha($source, true);
$rotation = imagerotate($source, $rotang, imageColorAllocateAlpha($source, 0, 0, 0, 127), 0);
imagealphablending($rotation, false);
imagesavealpha($rotation, true);
return $rotation;
}
?>
答案 0 :(得分:0)
这既不是虚线边界,也不是边界。之所以会发生这种情况,是因为您的图像分辨率较低,导致旋转边框变为“#34;中断”,因为实际像素不会旋转。
这就是我试图解释的内容:
一条平行于&#34;像素结构&#34;的线;一个px是三个破折号:
-------------------------------------
看起来很顺利。
旋转线:
---
---
---
---
---
---
---
如您所见,由于分辨率较低,它会逐步下降。
如果您使用更高的分辨率,问题就会消失。黑色&#34;的视觉效果。出现边框是因为您的白色图像与图像的其他部分形成对比。