@@ -35,6 +35,7 @@ class Image extends AbstractElement
35
35
const SOURCE_LOCAL = 'local ' ; // Local images
36
36
const SOURCE_GD = 'gd ' ; // Generated using GD
37
37
const SOURCE_ARCHIVE = 'archive ' ; // Image in archives zip://$archive#$image
38
+ const SOURCE_STRING = 'string ' ; // Image from string
38
39
39
40
/**
40
41
* Image source
@@ -379,6 +380,8 @@ private function checkImage($source)
379
380
// Check image data
380
381
if ($ this ->sourceType == self ::SOURCE_ARCHIVE ) {
381
382
$ imageData = $ this ->getArchiveImageSize ($ source );
383
+ } else if ($ this ->sourceType == self ::SOURCE_STRING ) {
384
+ $ imageData = $ this ->getStringImageSize ($ source );
382
385
} else {
383
386
$ imageData = @getimagesize ($ source );
384
387
}
@@ -416,9 +419,15 @@ private function setSourceType($source)
416
419
} elseif (strpos ($ source , 'zip:// ' ) !== false ) {
417
420
$ this ->memoryImage = false ;
418
421
$ this ->sourceType = self ::SOURCE_ARCHIVE ;
422
+ } elseif (filter_var ($ source , FILTER_VALIDATE_URL ) !== false ) {
423
+ $ this ->memoryImage = true ;
424
+ $ this ->sourceType = self ::SOURCE_GD ;
425
+ } elseif (@file_exists ($ source )) {
426
+ $ this ->memoryImage = false ;
427
+ $ this ->sourceType = self ::SOURCE_LOCAL ;
419
428
} else {
420
- $ this ->memoryImage = ( filter_var ( $ source , FILTER_VALIDATE_URL ) !== false ) ;
421
- $ this ->sourceType = $ this -> memoryImage ? self ::SOURCE_GD : self :: SOURCE_LOCAL ;
429
+ $ this ->memoryImage = true ;
430
+ $ this ->sourceType = self ::SOURCE_STRING ;
422
431
}
423
432
}
424
433
@@ -460,6 +469,24 @@ private function getArchiveImageSize($source)
460
469
return $ imageData ;
461
470
}
462
471
472
+ /**
473
+ * get image size from string
474
+ *
475
+ * @param string $source
476
+ *
477
+ * @codeCoverageIgnore this method is just a replacement for getimagesizefromstring which exists only as of PHP 5.4
478
+ */
479
+ private function getStringImageSize ($ source )
480
+ {
481
+ if (!function_exists ('getimagesizefromstring ' )) {
482
+ $ uri = 'data://application/octet-stream;base64, ' . base64_encode ($ source );
483
+ return @getimagesize ($ uri );
484
+ } else {
485
+ return @getimagesizefromstring ($ source );
486
+ }
487
+ return false ;
488
+ }
489
+
463
490
/**
464
491
* Set image functions and extensions.
465
492
*
0 commit comments