@@ -50,15 +50,16 @@ final class QrReader
5050{
5151 const SOURCE_TYPE_FILE = 'file ' ;
5252 const SOURCE_TYPE_BLOB = 'blob ' ;
53+ const SOURCE_TYPE_RESOURCE = 'resource ' ;
5354 public $ result ;
5455
55- function __construct ($ imgsource , $ sourcetype = 'file ' )
56+ function __construct ($ imgsource , $ sourcetype = 'file ' , $ isUseImagickIfAvailable = true )
5657 {
5758
5859 try {
5960 switch ($ sourcetype ) {
60- case ' file ' :
61- if (extension_loaded ('imagick ' )) {
61+ case QrReader:: SOURCE_TYPE_FILE :
62+ if ($ isUseImagickIfAvailable && extension_loaded ('imagick ' )) {
6263 $ im = new Imagick ();
6364 $ im ->readImage ($ imgsource );
6465 }else {
@@ -68,18 +69,28 @@ function __construct($imgsource, $sourcetype = 'file')
6869
6970 break ;
7071
71- case ' blob ' :
72- if (extension_loaded ('imagick ' )) {
72+ case QrReader:: SOURCE_TYPE_BLOB :
73+ if ($ isUseImagickIfAvailable && extension_loaded ('imagick ' )) {
7374 $ im = new Imagick ();
7475 $ im ->readimageblob ($ imgsource );
7576 }else {
7677 $ im = imagecreatefromstring ($ imgsource );
7778 }
7879
80+ break ;
81+
82+ case QrReader::SOURCE_TYPE_RESOURCE :
83+ $ im = $ imgsource ;
84+ if ($ isUseImagickIfAvailable && extension_loaded ('imagick ' )) {
85+ $ isUseImagickIfAvailable = true ;
86+ }else {
87+ $ isUseImagickIfAvailable = false ;
88+ }
89+
7990 break ;
8091 }
8192
82- if (extension_loaded ('imagick ' )) {
93+ if ($ isUseImagickIfAvailable && extension_loaded ('imagick ' )) {
8394 $ width = $ im ->getImageWidth ();
8495 $ height = $ im ->getImageHeight ();
8596 $ source = new \Zxing \IMagickLuminanceSource ($ im , $ width , $ height );
0 commit comments