PHP生成条形码类

本文阅读 1 分钟
首页 PHP笔记 正文
  1. //条形码
  2. function UPCAbarcode($code) {
  3. $trans_code = $code;
  4. $lw = 2.2; $hi = 40;
  5. $Lencode = array('0001101','0011001','0010011','0111101','0100011',
  6. '0110001','0101111','0111011','0110111','0001011');
  7. $Rencode = array('1110010','1100110','1101100','1000010','1011100',
  8. '1001110','1010000','1000100','1001000','1110100');
  9. $ends = '101'; $center = '01010';
  10. /* Compute the EAN-13 Checksum digit */
  11. $ncode = '0'.$code;
  12. $even = 0; $odd = 0;
  13. for ($x=0;$x<12;$x++) {
  14. if ($x % 2) {
  15. $odd += $ncode[$x];
  16. } else { $even += $ncode[$x];
  17. }
  18. }
  19. $code.=(10 - (($odd * 3 + $even) % 10)) % 10;
  20. /* Create the bar encoding using a binary string */
  21. $bars=$ends;
  22. $bars.=$Lencode[$code[0]];
  23. for($x=1;$x<6;$x++) {
  24. $bars.=$Lencode[$code[$x]];
  25. }
  26. $bars.=$center;
  27. for($x=6;$x<12;$x++) {
  28. $bars.=$Rencode[$code[$x]];
  29. }
  30. $bars.=$ends;
  31. /* Generate the Barcode Image */
  32. $img = ImageCreate($lw*75+200,$hi+30); // 矩形长宽
  33. $fg = ImageColorAllocate($img, 0, 0, 0);
  34. $bg = ImageColorAllocate($img, 255, 255, 255);
  35. ImageFilledRectangle($img, 0, 0, $lw*75+200, $hi+30, $bg); //渲染矩形
  36. $shift=10;
  37. for ($x=0;$x<strlen($bars);$x++) {
  38. if (($x<0) || ($x>=45 && $x<46) || ($x >=85)) {
  39. $sh=10;
  40. } else { $sh=0;
  41. }
  42. if ($bars[$x] == '1') {
  43. $color = $fg;
  44. } else { $color = $bg;
  45. }
  46. ImageFilledRectangle($img, ($x*$lw)+15,5,($x+1)*$lw+14,$hi+5+$sh,$color);
  47. }
  48. /* Add the Human Readable Label */
  49. ImageString($img,4,5,$hi-5,$code[0],$fg);
  50. for ($x=0;$x<5;$x++) {
  51. ImageString($img,5,$lw*(13+$x*6)+15,$hi+5,$code[$x+1],$fg);
  52. ImageString($img,5,$lw*(53+$x*6)+15,$hi+5,$code[$x+3],$fg);
  53. }
  54. ImageString($img,4,$lw*95-7,$hi,$code[11],$fg);
  55. /* Output the Header and Content. */
  56. header("Content-Type: image/png");
  57. ImagePNG($img,__UEURL__.'uploads/144.png');//保存图片
  58. }
解压密码: detechn或detechn.com

免责声明

本站所有资源出自互联网收集整理,本站不参与制作,如果侵犯了您的合法权益,请联系本站我们会及时删除。

本站发布资源来源于互联网,可能存在水印或者引流等信息,请用户自行鉴别,做一个有主见和判断力的用户。

本站资源仅供研究、学习交流之用,若使用商业用途,请购买正版授权,否则产生的一切后果将由下载用户自行承担。

php实现微信内置浏览器自动跳转其它浏览器
« 上一篇 08-21
PHP行执nodejs
下一篇 » 08-21

发表评论

惪特博客
  • 文章总数:
    18501 篇
  • 评论总数:
    53385 条
  • 标签总数:
    8881 个
  • 总浏览量:
    23388159 次
  • 最后更新:
    4月27日

最多点赞

随便看看

标签TAG