Giter Site home page Giter Site logo

Comments (3)

francoisjacquet avatar francoisjacquet commented on June 2, 2024 1

Hello @endroid

Thank you for your answer.

I have tried without xdebug, and the difference is huge.

There is now no notable difference between v5.0.7 and v1.9 :)

from qr-code.

francoisjacquet avatar francoisjacquet commented on June 2, 2024

In order to compare code for

  • version 1.9
   $qr_code = new QrCode();
   $qr_code
   	->setText( $_REQUEST['url'] )
   	->setSize( 280 ) // 300x300 = 150x150 (Student Photo) scale 2x.
   	->setPadding( 10 )
   	->setErrorCorrection( 'high' )
   	->setForegroundColor( ['r' => 0, 'g' => 0, 'b' => 0, 'a' => 0] )
   	->setBackgroundColor( ['r' => 255, 'g' => 255, 'b' => 255, 'a' => 0] )
   	->setLabel( ! empty( $_REQUEST['label'] ) ? $_REQUEST['label'] : '' )
   	->setImageType( QrCode::IMAGE_TYPE_PNG )
   ;

   // now we can directly output the qrcode
   header( 'Content-Type: ' . $qr_code->getContentType() );
   $qr_code->render();
  • version 5.0.7 (or 4.4.7 is almost the same)
	$qrCode = QrCode::create( $_REQUEST['url'] )
		->setEncoding( new Encoding( 'UTF-8' ) )
		->setErrorCorrectionLevel( ErrorCorrectionLevel::High )
		->setSize( 280 )
		->setMargin( 10 )
		->setForegroundColor( new Color( 0, 0, 0 ) )
		->setBackgroundColor( new Color( 255, 255, 255 ) );

	// Create generic label
	$label = Label::create( ! empty( $_REQUEST['label'] ) ? $_REQUEST['label'] : '' )
		->setTextColor( new Color( 0, 0, 0 ) );

	$writer = new PngWriter();

	$result = $writer->write( $qrCode, null, $label );

	// Directly output the QR code
	header( 'Content-Type: ' . $result->getMimeType() );
	echo $result->getString();

from qr-code.

endroid avatar endroid commented on June 2, 2024

Hi @francoisjacquet, when I run your last snippet here (exactly as you placed it) the code generates in approximataly 10ms. Of course I have different hardware here, but this difference is so big I think something else is going on, so I'm curious what is causing the performance issue on your side.

I don't know your exact url and label, can you provide those values to make sure it is not caused by specific values? Also, please check if you do not have underlying processes like xdebug running. And if it is really hard to find you could try to use a profiler like Blackfire. Such a tool makes finding the underlying cause a lot easier most of the cases.

from qr-code.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.