@@ -50,15 +50,16 @@ final class QrReader
50
50
{
51
51
const SOURCE_TYPE_FILE = 'file ' ;
52
52
const SOURCE_TYPE_BLOB = 'blob ' ;
53
+ const SOURCE_TYPE_RESOURCE = 'resource ' ;
53
54
public $ result ;
54
55
55
- function __construct ($ imgsource , $ sourcetype = 'file ' )
56
+ function __construct ($ imgsource , $ sourcetype = 'file ' , $ isUseImagickIfAvailable = true )
56
57
{
57
58
58
59
try {
59
60
switch ($ sourcetype ) {
60
- case ' file ' :
61
- if (extension_loaded ('imagick ' )) {
61
+ case QrReader:: SOURCE_TYPE_FILE :
62
+ if ($ isUseImagickIfAvailable && extension_loaded ('imagick ' )) {
62
63
$ im = new Imagick ();
63
64
$ im ->readImage ($ imgsource );
64
65
}else {
@@ -68,18 +69,28 @@ function __construct($imgsource, $sourcetype = 'file')
68
69
69
70
break ;
70
71
71
- case ' blob ' :
72
- if (extension_loaded ('imagick ' )) {
72
+ case QrReader:: SOURCE_TYPE_BLOB :
73
+ if ($ isUseImagickIfAvailable && extension_loaded ('imagick ' )) {
73
74
$ im = new Imagick ();
74
75
$ im ->readimageblob ($ imgsource );
75
76
}else {
76
77
$ im = imagecreatefromstring ($ imgsource );
77
78
}
78
79
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
+
79
90
break ;
80
91
}
81
92
82
- if (extension_loaded ('imagick ' )) {
93
+ if ($ isUseImagickIfAvailable && extension_loaded ('imagick ' )) {
83
94
$ width = $ im ->getImageWidth ();
84
95
$ height = $ im ->getImageHeight ();
85
96
$ source = new \Zxing \IMagickLuminanceSource ($ im , $ width , $ height );
0 commit comments