Qr code php base64

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

PHP library to produce QR Codes

License

lasalesi/phpqrcode

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

PHP library to produce QR Codes

This is PHP implementation of QR Code 2-D barcode generator. It is pure-php LGPL-licensed implementation based on C libqrencode by Kentaro Fukuchi.

It is tested to work with a standard Debian 9 (stretch), php7.0 and apache2.

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License (LICENSE file) for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

Читайте также:  Мастер серверы css v34

If you want to recreate cache by yourself make sure cache directory is writable and you have permisions to write into it. Also make sure you are able to read files in it if you have cache option enabled

Feel free to modify config constants in qrconfig.php file. Read about it in provided comments and project wiki page (links in README file)

Refer to the /samples section to get a quick start

Hardcoded QR code with settings, output to browser

WARNING! it should be FIRST and ONLY output generated by script, otherwise rest of output will land inside PNG binary, breaking it for sure

Code generated in text mode — as a binary table

$tab = $qr->encode('Test content'); QRspec::debug($tab, true); 

Inside bindings/tcpdf you will find slightly modified 2dbarcodes.php. Instal phpqrcode liblaty inside tcpdf folder, then overwrite (or merge) 2dbarcodes.php

Then use similar as example #50 from TCPDF examples:

 true, 'padding' => 4, 'fgcolor' => array(0,0,0), 'bgcolor' => false, //array(255,255,255) ); //code name: QR, specify error correction level after semicolon (L,M,Q,H) $pdf->write2DBarcode('PHP QR Code :)', 'QR,L', '', '', 30, 30, $style, 'N'); 

Uncaught Error: Call to undefined function ImageCreate()

In case this error appears (e.g. in /var/log/apache2/error.log once calling simple_qr.php), the GD library is not ready. Install it

$ sudo apt update && sudo apt install php-gd $ sudo service apache2 restart 

This project is based on the work of Dominik Dzienia on http://phpqrcode.sourceforge.net/

Based on C libqrencode library (ver. 3.1.1), Copyright (C) 2006-2010 by Kentaro Fukuchi, http://megaui.net/fukuchi/works/qrencode/index.en.html

QR Code is registered trademarks of DENSO WAVE INCORPORATED in JAPAN and other countries.

Reed-Solomon code encoder is written by Phil Karn, KA9Q. Copyright (C) 2002, 2003, 2004, 2006 Phil Karn, KA9Q

About

PHP library to produce QR Codes

Источник

Генерация QR-кода в PHP

Вопрос генерации QR-кодов в PHP достаточно освещён, есть много библиотек, одной из них является «PHP QR Code» – быстрый и легкий класс, рассмотрим его применение совместно с графической библиотекой GD.

Быстрый старт

Вывод в браузер:

require_once __DIR__ . '/phpqrcode/qrlib.php'; QRcode::png('https://snipp.ru/');

Сохранение в файл:

require_once __DIR__ . '/phpqrcode/qrlib.php'; QRcode::png('https://snipp.ru/', __DIR__ . '/qr.png');

Сгенерированный QR-код с базовыми настройками

Описание параметров

QRcode::png($text, $outfile, $level, $size, $margin, $saveandprint);

$text – текст, который будет закодирован в изображении. $outfile – куда сохранить файл, false – вывести в браузер. $level – уровень коррекции ошибок:

Значение Уровень Процент восстановления
L Низкий (по умолчанию) 7%
M Средний 15%
Q Четверть 25%
H Высокий 30%

Уровень коррекции ошибок - L

Уровень коррекции ошибок - M

Уровень коррекции ошибок - Q

Уровень коррекции ошибок - H

Размер «пикселя» - 4px

Размер «пикселя» - 6px

Размер «пикселя» - 8px

$margin – отступ от краев, задаётся в единицах, указанных в $size . $saveandprint – если true , то изображение одновременно сохранится в файле $outfile и выведется в браузер.

Данные в QR-коде

Для мобильных устройств, в данных можно использовать «протоколы приложений», тем самым при распознавании QR-кода сразу открыть нужное приложение, например набрать телефонный номер, написать письмо, открыть диалог в WhatsApp или Viber и т.д.

Читайте также:  Sign Up

Набрать номер телефона:

$text = 'tel:+7903xxxxxxx'; QRcode::png($text);

Написать SMS:

$text = 'sms:+7903xxxxxxx'; QRcode::png($text);

Добавить контакт:

$name = 'Иван Иванов'; $phone = '+7903xxxxxxx'; $text = 'BEGIN:VCARD' . "\n"; $text .= 'FN:' . $name . "\n"; $text .= 'TEL;WORK;VOICE:' . $phone . "\n"; $text .= 'END:VCARD'; QRcode::png($text);

Email:

$text = 'mailto:mail@example.com?subject=Тема письма'; QRcode::png($text);

Мессенджеры:

/* WhatsApp */ $text = 'whatsapp://send?phone=+7903xxxxxxx'; QRcode::png($text); /* Viber */ $text = 'viber://chat?number=+7903xxxxxxx'; QRcode::png($text); /* Skype */ $text = 'skype://логин?call'; QRcode::png($text);

Прозрачный фон

require_once __DIR__ . '/phpqrcode/qrlib.php'; /* Генерация QR-кода во временный файл */ QRcode::png('QR-код сгенерированный в PHP', __DIR__ . '/tmp.png', 'M', 6, 2); /* Замена белых пикселей на прозрачный */ $im = imagecreatefrompng(__DIR__ . '/tmp.png'); $width = imagesx($im); $height = imagesy($im); $bg_color = imageColorAllocate($im, 0, 0, 0); imagecolortransparent ($im, $bg_color); for ($x = 0; $x < $width; $x++) < for ($y = 0; $y < $height; $y++) < $color = imagecolorat($im, $x, $y); if ($color == 0) < imageSetPixel($im, $x, $y, $bg_color); >> > /* Вывод в браузер */ header('Content-Type: image/x-png'); imagepng($im);

Изменить цвет фона

require_once __DIR__ . '/phpqrcode/qrlib.php'; /* Генерация QR-кода во временный файл */ QRcode::png('QR-код сгенерированный в PHP - Snipp.ru', __DIR__ . '/tmp.png', 'M', 6, 2); $im = imagecreatefrompng(__DIR__ . '/tmp.png'); $width = imagesx($im); $height = imagesy($im); /* Цвет фона в RGB */ $bg_color = imageColorAllocate($im, 255, 145, 43); for ($x = 0; $x < $width; $x++) < for ($y = 0; $y < $height; $y++) < $color = imagecolorat($im, $x, $y); if ($color == 0) < imageSetPixel($im, $x, $y, $bg_color); >> > /* Вывод в браузер */ header('Content-Type: image/x-png'); imagepng($im);

Изменить цвет пикселей

require_once __DIR__ . '/phpqrcode/qrlib.php'; /* Генерация QR-кода во временный файл */ QRcode::png('QR-код сгенерированный в PHP - Snipp.ru', __DIR__ . '/tmp.png', 'M', 6, 2); $im = imagecreatefrompng(__DIR__ . '/tmp.png'); $width = imagesx($im); $height = imagesy($im); /* Цвет в RGB */ $fg_color = imageColorAllocate($im, 0, 133, 178); for ($x = 0; $x < $width; $x++) < for ($y = 0; $y < $height; $y++) < $color = imagecolorat($im, $x, $y); if ($color == 1) < imageSetPixel($im, $x, $y, $fg_color); >> > /* Вывод в браузер */ header('Content-Type: image/x-png'); imagepng($im);

Инверсия цветов

require_once __DIR__ . '/phpqrcode/qrlib.php'; /* Генерация QR-кода во временный файл */ QRcode::png('QR-код сгенерированный в PHP - Snipp.ru', __DIR__ . '/tmp.png', 'M', 6, 2); $im = imagecreatefrompng(__DIR__ . '/tmp.png'); imagefilter($im, IMG_FILTER_NEGATE); /* Вывод в браузер */ header('Content-Type: image/x-png'); imagepng($im);

Логотип в центре

Если у QR-кода поднять уровень коррекции ошибок до максимального, то можно спокойно вставить логотип без потери читаемости. Phpqrcode генерирует изображение в формате PNG-8, поэтому потребуется преобразовать его в PNG-24, чтобы избежать потерю цветов у логотипа.

require_once __DIR__ . '/phpqrcode/qrlib.php'; /* Генерация QR-кода во временный файл */ QRcode::png('QR-код сгенерированный в PHP - Snipp.ru', __DIR__ . '/tmp.png', 'H', 6, 2); /* Конвертация PNG8 в PNG24 */ $im = imagecreatefrompng(__DIR__ . '/tmp.png'); $width = imagesx($im); $height = imagesy($im); $dst = imagecreatetruecolor($width, $height); imagecopy($dst, $im, 0, 0, 0, 0, $width, $height); imagedestroy($im); /* Наложение логотипа */ $logo = imagecreatefrompng(__DIR__ . '/logo.png'); $logo_width = imagesx($logo); $logo_height = imagesy($logo); $new_width = $width / 3; $new_height = $logo_height / ($logo_width / $new_width); $x = ceil(($width - $new_width) / 2); $y = ceil(($height - $new_height) / 2); imagecopyresampled($dst, $logo, $x, $y, 0, 0, $new_width, $new_height, $logo_width, $logo_height); /* Вывод в браузер */ header('Content-Type: image/x-png'); imagepng($dst);

Источник

Читайте также:  Css contact form styling

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

License

Codigos-Ajenos/php-qr-code

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

This source is base in v1.1.4 (2010100721) of phpqrcode.sourceforge.net
I just modified and fixed a little bit of code.

QUICK START WIDTH COMPOSER

composer require jysperu/php-qr-code

 require_once '/path/to/vendor/autoload.php';

QUICK START WIDTHOUT COMPOSER

 spl_autoload_register(function ($class) < static $dir = '/path/to/src'; static $spc = '\\'; $class = trim($class, $spc); $parts = explode($spc, $class); $base = array_shift($parts); if ($base <> 'QRcode' or count($parts) === 0) return; $parts = implode(DIRECTORY_SEPARATOR, $parts); $file = $dir . DIRECTORY_SEPARATOR . $parts . '.php'; if (file_exists($file)) require_once $file; >);
use QRcode\QRcode; use QRcode\QRstr; $data = 'Hello World!'; $dest = __DIR__ . '/qr.png'; QRcode :: png ($data, $dest, QRstr :: QR_ECLEVEL_L, 4, 2); ## Expected: New file
use QRcode\QRcode; use QRcode\QRstr; $data = 'Hello World!'; $dest = __DIR__ . '/qr.webp'; QRcode :: webp ($data, $dest, QRstr :: QR_ECLEVEL_L, 4, 2); ## Expected: New file
use QRcode\QRcode; use QRcode\QRstr; $data = 'Hello World!'; QRcode :: png ($data, FALSE, QRstr :: QR_ECLEVEL_L, 4, 2); ## Expected: Header: Content-type: image/png
use QRcode\QRcode; use QRcode\QRstr; $data = 'Hello World!'; QRcode :: webp ($data, FALSE, QRstr :: QR_ECLEVEL_L, 4, 2); ## Expected: Header: Content-type: image/webp
use QRcode\QRcode; use QRcode\QRstr; $data = 'Hello World!'; $base64_data = QRcode :: base64_png ($data, QRstr :: QR_ECLEVEL_L, 4, 2); ## Expected: $base64_data = data:image/png;base64. 
use QRcode\QRcode; use QRcode\QRstr; $data = 'Hello World!'; $base64_data = QRcode :: base64_webp ($data, QRstr :: QR_ECLEVEL_L, 4, 2); ## Expected: $base64_data = data:image/webp;base64. 

Источник

Оцените статью