i have script replaces black or white color color chosen user, works ok on colors (purple background green writing) leaves white pixelated border around letters? cant figure out do? see here - http://marijasorganicpantry.com.au/imagephp.php
<?php ob_start(); $txtcolor=$_request['text1']; $r1txt=hexdec(substr($txtcolor,0,2)); $g1txt=hexdec(substr($txtcolor,2,2)); $b1txt=hexdec(substr($txtcolor,4,2)); $backcolor=$_request['back1']; $r1back=hexdec(substr($backcolor,0,2)); $g1back=hexdec(substr($backcolor,2,2)); $b1back=hexdec(substr($backcolor,4,2)); $imgname="demo_the-crown-prints_work-hard_5x7.jpg"; $im = imagecreatefromjpeg($imgname); $w = imagesx($im); $h = imagesy($im); $gd = imagecreatetruecolor($w,$h); imagecopyresampled($gd, $im, 0, 0, 0, 0, $w, $h, $w, $h); imagefilter($gd, img_filter_colorize,$r1txt,$g1txt,$b1txt); for($x=0;$x<$w;$x++) { for($y=0;$y<$h;$y++) { $rgb = imagecolorat($gd, $x, $y); $r = ($rgb >> 16) & 0xff; $g = ($rgb >> 8) & 0xff; $b = $rgb & 0xff; if ($r==255 , $g==255 , $b==255) { $pixelcolor=imagecolorallocatealpha($gd,$r1back,$g1back,$b1back,10); imagesetpixel($gd,$x,$y,$pixelcolor); } } } imagejpeg($gd,null,100); $outputbuffer = ob_get_clean(); $base64 = base64_encode($outputbuffer); echo '<a id="downloadimage" style="text-decoration:none;" download> <img id="image2" width=150 height=250 src="data:image/jpeg;base64,'.$base64.'" /> <li style="padding-top:7px;textalign:center;display:block;border-radius:10px;background-color:royaleblue;height:30px;width:100px;">download</li></a>'; ?>
because in original image letters have border not perfect black, color not
r = 0 g = 0 b = 0
i have change little bit original code avoid unnecessary steps. need?
<?php ob_start(); $txtcolor="20ff00"; $r1txt=hexdec(substr($txtcolor,0,2)); $g1txt=hexdec(substr($txtcolor,2,2)); $b1txt=hexdec(substr($txtcolor,4,2)); $backcolor="ff0ed9"; $r1back=hexdec(substr($backcolor,0,2)); $g1back=hexdec(substr($backcolor,2,2)); $b1back=hexdec(substr($backcolor,4,2)); $imgname="demo_the-crown-prints_work-hard_5x7.jpg"; $gd = imagecreatefromjpeg($imgname); $w = imagesx($gd); $h = imagesy($gd); for($x=0;$x<$w;$x++) { for($y=0;$y<$h;$y++) { $rgb = imagecolorat($gd, $x, $y); $r = ($rgb >> 16) & 0xff; $g = ($rgb >> 8) & 0xff; $b = $rgb & 0xff; if ($r>200 && $g>200 && $b>200) { $pixelcolor=imagecolorallocate($gd,$r1back,$g1back,$b1back); imagesetpixel($gd,$x,$y,$pixelcolor); } else { $pixelcolor=imagecolorallocate($gd,$r1txt,$g1txt,$b1txt); imagesetpixel($gd,$x,$y,$pixelcolor); } } } imagejpeg($gd,'simpletext.jpg', 100); imagepng($gd,'simpletext.png', 0); ?>
i have saved result on files let see difference of quality between imagejpeg , imagepng
Comments
Post a Comment