haardys Posted January 18, 2011 Report Share Posted January 18, 2011 Nepieciešams webā pulbiskot svītrkodus. It kā nokačāju fontu EAN-13, bet īsti nestrādā. Tad jautājums - to fontu vajag definēt caur CSS vai vabūt JS? Un cik liela iespējamība, ka kādam uz kompja netiks atrādīts šis fonts? Link to comment Share on other sites More sharing options...
rATRIJS Posted January 18, 2011 Report Share Posted January 18, 2011 http://nicewebtype.com/notes/2009/10/30/how-to-use-css-font-face/ Link to comment Share on other sites More sharing options...
briedis Posted January 18, 2011 Report Share Posted January 18, 2011 Es visdrīzāk to risinātu tā, ka tie kodi tiktu zīmēti ar php un attēloti kā bildes. Rezultātā izmantotu kā: <img src="bar_code.php?code=...."/> vismaz ar garantiju :) Link to comment Share on other sites More sharing options...
haardys Posted January 18, 2011 Author Report Share Posted January 18, 2011 Paldies, Briedi, laba ideja. A varbūt ir kāds koda paraugs šim variantam? Link to comment Share on other sites More sharing options...
Blitz Posted January 18, 2011 Report Share Posted January 18, 2011 Pilna google: http://www.google.lv/#sclient=psy&hl=en&q=php+barcode+generator+&aq=f&aqi=g4g-o1&aql=f&oq=&pbx=1&fp=2eb0866f3aa94559 Link to comment Share on other sites More sharing options...
rATRIJS Posted January 18, 2011 Report Share Posted January 18, 2011 http://uk3.php.net/manual/en/function.imagettftext.php Link to comment Share on other sites More sharing options...
haardys Posted January 18, 2011 Author Report Share Posted January 18, 2011 class CaptchaSecurityImages { var $font = 'EAN-13.TTF'; function generateCode($characters) { /* list all possible characters, similar looking characters and vowels have been removed */ //$possible = '0123456789'; $code = '123456789'; //$i = 0; //while ($i < $characters) { // $code .= substr($possible, mt_rand(0, strlen($possible)-1), 1); // $i++; //} return $code; } function CaptchaSecurityImages($width='120',$height='40',$characters='13') { $code = $this->generateCode($characters); /* font size will be 75% of the image height */ $font_size = $height * 0.75; $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream'); /* set the colours */ $background_color = imagecolorallocate($image, 255, 255, 255); $text_color = imagecolorallocate($image, 20, 40, 100); // $noise_color = imagecolorallocate($image, 100, 120, 180); /* create textbox and add text */ $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function'); $x = ($width - $textbox[4])/2; $y = ($height - $textbox[5])/2; imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function'); /* output captcha image to browser */ header('Content-Type: image/jpeg'); imagejpeg($image); imagedestroy($image); $_SESSION['security_code'] = $code; } } $captcha = new CaptchaSecurityImages($width,$height,$characters); Viss būtu ok, itkā bracode izveido ar vērtību, kādu nodefinēju mainīgajam $code. Bet man vajadzētu, ka to $code vērtība tiktu ņemta no datu bāzēs. Link to comment Share on other sites More sharing options...
Blitz Posted January 18, 2011 Report Share Posted January 18, 2011 (edited) 1) Japiesledzas datu bazei 2) Jauzraksta SQL pieprasijums un jaizpilda tas 3) Jadabun atgrieztie dati 4) Japadod dati generateCode f-jai / metodei Ko tieši nesaproti? Edited January 18, 2011 by Blitz Link to comment Share on other sites More sharing options...
Grey_Wolf Posted January 18, 2011 Report Share Posted January 18, 2011 Es visdrīzāk to risinātu tā, ka tie kodi tiktu zīmēti ar php un attēloti kā bildes. Rezultātā izmantotu kā: <img src="bar_code.php?code=...."/> vismaz ar garantiju :) Vel ir risinajums fontus parverst par bildiitem ieksh Photoshop etc. un atradiit jau gatavas bildiites -> buus daudz atrak un tiesham ar garantiju .. tb. pashu kodu sastadiit no vairakam bildiitem Link to comment Share on other sites More sharing options...
daGrevis Posted January 18, 2011 Report Share Posted January 18, 2011 Bet tad rodas mīnuss, ka doto attēlu (kas īstenībā ir vairāki attēli kopā_ nevar saglabāt kā vienu attēlu. =( Bet ja tas nav vajadžīgs, tad tas arī ir risinājums. =) Link to comment Share on other sites More sharing options...
haardys Posted January 18, 2011 Author Report Share Posted January 18, 2011 1) Japiesledzas datu bazei 2) Jauzraksta SQL pieprasijums un jaizpilda tas 3) Jadabun atgrieztie dati 4) Japadod dati generateCode f-jai / metodei Ko tieši nesaproti? Tieši kā padot tos datus f-jai! Pie datu bāzes datiem tieku, bet tālāk nesanāk.. Respektīvi uzģenerētais attēls netiek atrādīts! Link to comment Share on other sites More sharing options...
Blitz Posted January 19, 2011 Report Share Posted January 19, 2011 (edited) function CaptchaSecurityImages($width='120',$height='40',$characters='13',$code) { //pieiveno pie parametriem $code //sis vairs nav vajadzigs //$code = $this->generateCode($characters); .... } pec ta, izsauc kā $code=$_GET['code']; $captcha = new CaptchaSecurityImages($width,$height,$characters,$code); So visu glabā failā, piemēram barcode.php. Tad kādā citā failā while($row=mysql_fetch_assoc($result)) { //izdruka katram kodam no datu bazes bilditi echo "<img src='./barcode.php?code=$row[barcode]' />"; } Edited January 19, 2011 by Blitz Link to comment Share on other sites More sharing options...
Grey_Wolf Posted January 19, 2011 Report Share Posted January 19, 2011 Tieši kā padot tos datus f-jai! Pie datu bāzes datiem tieku, bet tālāk nesanāk.. Respektīvi uzģenerētais attēls netiek atrādīts! Padoma vai katru reizi gribeesi generet taas images? ja dati tiek glabati datubaaze, tad iespejams ka vienkrshak ir uzreiz uzgenereet attelus, un vinjus pieglabat uz diska, attieciigi DB ierakstot attela nosukumu, vai arii izmantot nosaukumam to kodu (piem 123456.jpg -> no DB dabuun 123456 un piekabini klat .jpg) katkaa shadi.. <?php function svitru_kods($code,$celjsh_kur_pieglabaat,$width='120',$height='40',$characters='13') { $font='arial.ttf'; /* font size will be 75% of the image height */ $font_size = $height * 0.75; $image = imagecreate($width, $height) or die('Cannot initialize new GD image stream'); /* set the colours */ $background_color = imagecolorallocate($image, 255, 255, 255); $text_color = imagecolorallocate($image, 20, 40, 100); /* create textbox and add text */ $textbox = imagettfbbox($font_size, 0, $font, $code) or die('Error in imagettfbbox function'); $x = ($width - $textbox[4])/2; $y = ($height - $textbox[5])/2; imagettftext($image, $font_size, 0, $x, $y, $text_color, $font , $code) or die('Error in imagettftext function'); /* output captcha image to browser */ // imagejpeg($image,$celjsh_kur_pieglabaat.$code.'.jpg'); imagedestroy($image); } $celjsh_kur_pieglabaat='aaa/'; // bildes direktorija $kods='1234'; // kods svitru_kods($kods, $celjsh_kur_pieglabaat); ?> <img src="<?php echo $celjsh_kur_pieglabaat.$kods.'.jpg';?>"> Pieglabas direktorijaa aaa Link to comment Share on other sites More sharing options...
haardys Posted January 19, 2011 Author Report Share Posted January 19, 2011 Beidzot viss izdevās! Bet tagad atkal ir problēma ar svītrkoda nolasīšanu - svītrkods uzģenerēts, bet nevar nolasīt. Liekas, ka problēma ar fontu (?), jo to pašu kombināciju uzģenerējot kādā online barcode ģenerētājā, tad šie attēli atškiras.. bet fonts itkā viens un tas pats! Link to comment Share on other sites More sharing options...
daGrevis Posted January 19, 2011 Report Share Posted January 19, 2011 Ja ir daudz attēla daļas, tad skaties, lai starp viņiem nav nekādas atstarpes utml.. Link to comment Share on other sites More sharing options...
Recommended Posts