Unwanted dashed black border when rotating image in php -
i getting unwanted dashed black border when rotate image. have tried remove not finding success. using following function image rotation. try preserve transparency. have provided image well.
here 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; }
i call function that:
$rotatedimage = imagerotation($image, 10);
here full code
<?php // settings $text = "previously blogging"; $fontface = 'days.ttf'; $fontsize = 90; $angle = 0; $bbox = calculatetextbox($text, $fontface, $fontsize, $angle); $image = imagecreatetruecolor($bbox['width'], $bbox['height']); // define colors $black = imagecolorallocate($image, 0, 0, 0); $yellow = imagecolorallocate($image, 0xff, 0xff, 0xff); //fill image 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 1 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; } ?>
this neither dashed border, nor border @ actually. happens because images low-resolution, cause the rotated borders "break", because actual pixels don't rotate.
that's i'm trying explain:
a line, parallel "pixel construction"; 1 px 3 dashes long:
-------------------------------------
it smooth.
rotated line:
--- --- --- --- --- --- ---
as see, due low resolution, steps, not smoothly goes down.
if use higher resolution, issue go away. visual effect of "black" border appears because white image contrasts other part of image.
Comments
Post a Comment