Гость
Покинул форум
Сообщений всего: 84
Дата рег-ции: Май 2011
Помог: 0 раз(а)
|
Никогда не работал с изображениями в php, помогите мне убрать фон у капчи (сделать прозрачным)
PHP:
скопировать код в буфер обмена
$symbol=0; $reading_symbol=false; $alphabet = "0123456789"; $alphabet_length = strlen($alphabet); for($i=0;$i<$fontfile_width && $symbol<$alphabet_length;$i++){ if(!$reading_symbol && !$transparent){ $font_metrics[$alphabet{$symbol}]=array('start'=>$i); $reading_symbol=true; continue; } if($reading_symbol && $transparent){ $font_metrics[$alphabet{$symbol}]['end']=$i; $reading_symbol=false; $symbol++; continue; } } $background_color = array(255 ,255 ,255 ); $foreground_color = array(70 ,70 ,70 ); $string = ''; $x = 5; $y = 5; for ($i=0;$i<6;$i++) { $string .= $char; if ($x > 15) $x = $x - 2; imagecopy($image,$font,$x,$y,$font_metrics[$char]['start'],1 ,$font_metrics[$char]['end']-$font_metrics[$char]['start'],42 ); $x += $font_metrics[$char]['end']-$font_metrics[$char]['start']; } for ($i=0;$i<10;$i++) { ImageSmoothAlphaLine ($image,Rand(5 ,$width*0 .5 ),Rand(5 ,$height-5 ),rand($width*0 .5 ,$width-5 ),rand(5 ,$height-5 ),255 ,255 ,255 );} for ($i=0;$i<2;$i++) { ImageSmoothAlphaLine ($image,rand(5 ,10 ),Rand(5 ,$height-5 ),rand($width-10 ,$width-5 ),rand(5 ,$height-5 ),0 ,0 ,0 );} $center=$x/2; $rand1=mt_rand(750000 ,1200000 )/10000000; $rand2=mt_rand(750000 ,1200000 )/10000000; $rand3=mt_rand(750000 ,1200000 )/10000000; $rand4=mt_rand(750000 ,1200000 )/10000000; for($x=0;$x<ImageSX($image);$x++){ for($y=0;$y<ImageSY($image);$y++){ $sx=$x+(sin($x*$rand1+$rand5)+sin($y*$rand3+$rand6))*$rand9-$width/2 +$center+1; $sy=$y+(sin($x*$rand2+$rand7)+sin($y*$rand4+$rand8))*$rand10; if($sx<0 || $sy<0 || $sx>=$width-1 || $sy>=$height-1){ $color=255; $color_x=255; $color_y=255; $color_xy=255; }else{ } if($color==0 && $color_x==0 && $color_y==0 && $color_xy==0){ $newred=$foreground_color[0]; $newgreen=$foreground_color[1]; $newblue=$foreground_color[2]; }else if($color==255 && $color_x==255 && $color_y==255 && $color_xy==255){ $newred=$background_color[0]; $newgreen=$background_color[1]; $newblue=$background_color[2]; }else{ $frsx1=1-$frsx; $frsy1=1-$frsy; $newcolor=( $color*$frsx1*$frsy1+ $color_x*$frsx*$frsy1+ $color_y*$frsx1*$frsy+ $color_xy*$frsx*$frsy); if($newcolor>255) $newcolor=255; $newcolor=$newcolor/255; $newcolor0=1-$newcolor; $newred=$newcolor0*$foreground_color[0]+$newcolor*$background_color[0]; $newgreen=$newcolor0*$foreground_color[1]+$newcolor*$background_color[1]; $newblue=$newcolor0*$foreground_color[2]+$newcolor*$background_color[2]; } } } $_SESSION['sec_code_session'] = $string; $wm_pos_x = ((160) - ($wm_width)); imagecopy($img2, $watermark, $wm_pos_x, 1 , 0 , 0 , $wm_width, $wm_height); header("content-type: image/png"); function ImageSmoothAlphaLine ($image, $x1, $y1, $x2, $y2, $r, $g, $b, $alpha=0) { $icr = $r; $icg = $g; $icb = $b; if ($y1 == $y2 || $x1 == $x2) imageline($image, $x1, $y2, $x1, $y2, $dcol); else { $m = ($y2 - $y1) / ($x2 - $x1); $b = $y1 - $m * $x1; $endx = max($x1, $x2) + 1; while ($x < $endx) { $y = $m * $x + $b; $tcr = ($trgb >> 16) & 0xFF; $tcg = ($trgb >> 8) & 0xFF; $tcb = $trgb & 0xFF; $tcr = ($trgb >> 16) & 0xFF; $tcg = ($trgb >> 8) & 0xFF; $tcb = $trgb & 0xFF; $x++; } } else { $endy = max($y1, $y2) + 1; while ($y < $endy) { $x = ($y - $b) / $m; $tcr = ($trgb >> 16) & 0xFF; $tcg = ($trgb >> 8) & 0xFF; $tcb = $trgb & 0xFF; $tcr = ($trgb >> 16) & 0xFF; $tcg = ($trgb >> 8) & 0xFF; $tcb = $trgb & 0xFF; $y ++; } } } }
|