Please tell me step by step, I'm amateur on php.
visit here
How to use this code.
Please help or guide me to make this code work 100%.
require __DIR__ . "/vendor/autoload.php";
$qrcode = new QrReader('path/to_image');
$text = $qrcode->text(); //return decoded text from QR Code`
QR code decoder / reader for PHP
This is a PHP library to detect and decode QR-codes.
This is first and only QR code reader that works without extensions.
Ported from ZXing library
Installation
The recommended method of installing this library is via Composer.
Run the following command from your project root:
$ composer require khanamiryan/qrcode-detector-decoder
Usage
require __DIR__ . "/vendor/autoload.php";
$qrcode = new QrReader('path/to_image');
$text = $qrcode->text(); //return decoded text from QR Code
I'm making this an answer because it is too complex for a comment.
First of all you should really try to use this code before asking for help. But let's look at the proposed code anyway:
<?php
// This line calls the autoload script generated by Composer. This ensures that you can
// just use the library classes without having to manually include their specific files
require __DIR__ . "/vendor/autoload.php";
// This instantiates the QrReader class and points it to the path of a QR code image
$qrcode = new QrReader('path/to_image');
// This calls the text method on the above instance to determine the contents of the qr code
$text = $qrcode->text();
if this doesn't work for you then you should post the error(s) you got. If you can't see any errors then add the following right below the <?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
I had a lot of trouble to get this working library without composer too.
The thing is it works on windows but not on linux because of the wrong capitalization of filenames and directories and such.
Then I found this blog that has a great solution:
https://www.mgcwebsites.co.uk/solved-class-zxinggdluminancesource-not-found/
Install a version before Composer support was added
Perhaps you use shared hosting that doesn’t allow you to install Composer or use SSH. Perhaps, like me, your server works perfectly and you want to keep it as clean as possible. Either way checking through the commits I was pleased to see Composer support is a fairly recent addition and that by downloading the last commit before Composer support was added I was able to forget about Composer and get the library working in seconds.
https://github.com/khanamiryan/php-qrcode-detector-decoder/tree/cda63b7f4a8cd84d72c41b25c74284b56dc7f2cc
It works very well now...
Related
I have used the quickstart instructions on:
https://cloud.google.com/text-to-speech/docs/quickstart-client-libraries#client-libraries-install-php to set up a Google Cloud Platform project on ubuntu 16.04 to create speech from text using php.
I believe I have successfully completed all the instructions:
enabled the text to speech API
set up authentication created service account key
set the GOOGLE_APPLICATION_CREDENTIALS environment variable to the path of the key file and verifed that by entering
echo $GOOGLE_APPLICATION_CREDENTIALS at the command line.
installed the Cloud SDK, run gcloud init and got no errors
installed the library with composer require google/cloud-text-to-speech
Now, when I try to run the example php code...
// includes the autoloader for libraries installed with composer
require __DIR__ . '/vendor/autoload.php';
// Imports the Cloud Client Library
use Google\Cloud\TextToSpeech\V1\AudioConfig;
use Google\Cloud\TextToSpeech\V1\AudioEncoding;
use Google\Cloud\TextToSpeech\V1\SsmlVoiceGender;
use Google\Cloud\TextToSpeech\V1\SynthesisInput;
use Google\Cloud\TextToSpeech\V1\TextToSpeechClient;
use Google\Cloud\TextToSpeech\V1\VoiceSelectionParams;
// instantiates a client
$client = new TextToSpeechClient();
// sets text to be synthesised
$synthesisInputText = (new SynthesisInput())
->setText('Hello, world!');
// build the voice request, select the language code ("en-US") and the ssml
// voice gender
$voice = (new VoiceSelectionParams())
->setLanguageCode('en-US')
->setSsmlGender(SsmlVoiceGender::FEMALE);
// Effects profile
$effectsProfileId = "telephony-class-application";
// select the type of audio file you want returned
$audioConfig = (new AudioConfig())
->setAudioEncoding(AudioEncoding::MP3)
->setEffectsProfileId(array($effectsProfileId));
// perform text-to-speech request on the text input with selected voice
// parameters and audio file type
$response = $client->synthesizeSpeech($synthesisInputText, $voice, $audioConfig);
$audioContent = $response->getAudioContent();
// the response's audioContent is binary
file_put_contents('output.mp3', $audioContent);
echo 'Audio content written to "output.mp3"' . PHP_EOL;
... I get
PHP Fatal error: Uncaught DomainException: Could not load the default credentials. Browse to https://developers.google.com/accounts/docs/application-default-credentials for more information in /var/www/my-domain/folder/vendor/google/auth/src/ApplicationDefaultCredentials.php:168
If I use the command line to create the audio, it works fine, so the account, authorisation and the SDK would appear to be configured correctly.
It is the first time I have used GCP, so I fully expect I'm missing something obvious. Help much appreciated.
EDIT:
Problem solved by adding:
putenv('GOOGLE_APPLICATION_CREDENTIALS=/path/to/key/key.json');
after importing the cloud library and before instantiating the client object.
I'm using Eclipse to develop a server written in PHP
I am now using tracy https://tracy.nette.org/ to retrieve debug information. It works and it's great to get cold and rich informations
<?php
require_once 'tracy.phar';
use Tracy\Debugger;
Debugger::enable(Debugger::DETECT, __DIR__ . '/mylog');
I got red alerts from Eclipse: The import Tracy\Debugger cannot be resolved
Any clue ?
Thanks
Found !
Project Properties > Include Path to external PHAR
Don't forget to clean the project, to check build automatically
and then the include Phar libray is taken into consideration, at least...
What is the minimum "hello world" example for TCPDF?
I see over 60 examples at https://tcpdf.org/examples/ and none of them work with composer and they are all very complicated.
I'm looking for something simple so I can start learning off of that.
The title of the post specifies that they want to use TCPDF with Composer and I found that the accepted answer does not utilize Composer to do this.
First, include TCPDF in Composer. Add the following code to your composer.json file:
"require": {
"tecnickcom/tcpdf": "^6.2.13"
}
If there is an existing composer.lock file in the directory, then run from the command-line:
composer install
Otherwise, run from the command-line:
composer update
Create a PHP file with the following code:
<?php
// Load autoloader (using Composer)
require __DIR__ . '/vendor/autoload.php';
$pdf = new TCPDF(); // create TCPDF object with default constructor args
$pdf->AddPage(); // pretty self-explanatory
$pdf->Write(1, 'Hello world'); // 1 is line height
$pdf->Output('hello_world.pdf'); // send the file inline to the browser (default).
?>
Open this page from your web browser and you should see an example PDF document saying Hello World.
I want to use Supervisor to manager my processes. I have got it installed on my Amazon linux Machine and the basic setup runs fine as per the config file.
Now, I want to change the processes dynamically. Since it needs the config file to be changed every time and a restart, using PHP library to do the same seems to be a good option.
Specifically I am going through SupervisorPHP config to change the configuration dynamically and SupervisorPHP to manager Supervisor through PHP.
Following the README for SupervisorPHP config, I got it installed via composer
composer require supervisorphp/configuration
I copied the sample code
<?php
use Supervisor\Configuration\Configuration;
use Supervisor\Configuration\Section\Supervisord;
use Supervisor\Configuration\Section\Program;
use Indigophp\Ini\Rendere;
$config = new Configuration;
$renderer = new Renderer;
$section = new Supervisord(['identifier' => 'supervisor']);
$config->addSection($section);
$section = new Program('test', ['command' => 'cat']);
$config->addSection($section);
echo $renderer->render($config->toArray());
When I run this code, I get the following error:
PHP Fatal error: Class 'Supervisor\Configuration\Configuration' not found in test.php on line 7
I also tried to clone the repo and include the files individually, however it shows error for other dependencies. It would be great if I could use this.
There are 2 mistakes in the above code.
The first mistake is that you do not use the autoloader provided by composer so that php can find the necessary classes. To do so just add require __DIR__ . '/vendor/autoload.php'; (If the vendor folder is in a different path relative to the sample script then adjust accordingly).
The second mistake is in the use statement for Indigophp. Apart from the obvious typo in the word Renderer, if you check the source of Indigo you will see that it must be use Indigo\Ini\Renderer;
So the correct code to test your installation is:
<?php
require __DIR__ . '/vendor/autoload.php';
use Supervisor\Configuration\Configuration;
use Supervisor\Configuration\Section\Supervisord;
use Supervisor\Configuration\Section\Program;
use Indigo\Ini\Renderer;
$config = new Configuration;
$renderer = new Renderer;
$section = new Supervisord(['identifier' => 'supervisor']);
$config->addSection($section);
$section = new Program('test', ['command' => 'cat']);
$config->addSection($section);
echo $renderer->render($config->toArray());
Running the above code, you should get the following output:
[supervisord]
identifier = supervisor
[program:test]
command = cat
I want to use the composer/composer PHP classes to update individual plugin packages.
I do not want to use command-line solutions like exec("php composer.phar update");
I am unable to get it to work. I have tried several different options, much alike the following code.
It just returns a blank screen.
use Composer\Console\Application;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
$input = new ArrayInput(array('command' => 'require vendor/packkage dev-master'));
$output = new BufferedOutput();
$application = new Application();
$application->run($input, $output);
dd($output->fetch());
Things i would like to achieve:
Download/Update individual packages
Get result output to verify success
Dump autoload
Remove/require packages
A bit of context details:
I am creating a plugin updater for my PHP application (in admin panel).
Every plugin is a composer package and resides on my own Satis repository.
The plugins get installed into a custom dir using my composer plugin.
I can read composer.lock locally and packages.json on the satis server to figure out
what packages require updates.
update
I've managed to at least get it to work. The no-output issue was due to $application->setAutoExit that needed to be false before running. Next issue that i had was that the required package would download itself into the same directory as the class where i called it from. Solved that by using putenv and chdir. Result:
root/comp.php
putenv('COMPOSER_HOME=' . __DIR__ . '/vendor/bin/composer');
chdir(__DIR__);
root/workbench/sumvend/sumpack/src/PackageManager.php
include(base_path() . '/comp.php');
$input = new ArrayInput(array('command' => 'require', 'packages' => ['vend/pak dev-master']));
$output = new BufferedOutput();
$application = new Application();
$application->setAutoExit(false);
$application->run($input, $output); //, $output);
dd($output->fetch());
This works, but it's far from ideal.
The full solution to this would be pretty long winded, but I will try to get you on the right track.
php composer.phar require composer/composer dev-master
You can load the source of composer into your project vendors. You might have already done this.
The code you are looking for is at: Composer\Command\RequireCommand.
$install = Installer::create($io, $composer);
$install
->setVerbose($input->getOption('verbose'))
->setPreferSource($input->getOption('prefer-source'))
->setPreferDist($input->getOption('prefer-dist'))
->setDevMode($updateDevMode)
->setUpdate(true)
->setUpdateWhitelist(array_keys($requirements))
->setWhitelistDependencies($input->getOption('update-with-dependencies'));
;
$status = $install->run();
Most of the command relates to the reading and writing to of the composer.json file.
However the installer itself is independent of where the configuration actually came from. You could in theory store the configuration in a database.
This is the static create method for the installer:
public static function create(IOInterface $io, Composer $composer)
{
return new static(
$io,
$composer->getConfig(),
$composer->getPackage(),
$composer->getDownloadManager(),
$composer->getRepositoryManager(),
$composer->getLocker(),
$composer->getInstallationManager(),
$composer->getEventDispatcher(),
$composer->getAutoloadGenerator()
);
}
You will need to pay special attention to the Package, And implement your own.
Although your current attempt to run it on the command line will work, I do not recommend it because Composer is primarily a development and deployment utility, not an application utility.
In order to smoothly use it to assist with loading plugins on a production environment, you will need to tightly integrate its internals with your own application, not just use it on the side.
This is something I am interested in as well, and I think this has inspired me to look into it myself. So I'll let you know what I come up with, but this is the best I can advise you for now on what I consider to be the correct approach.