@@ -340,6 +340,8 @@ public function getImageStringData($base64 = false)
340
340
call_user_func ($ this ->imageFunc , $ imageResource );
341
341
$ imageBinary = ob_get_contents ();
342
342
ob_end_clean ();
343
+ } elseif ($ this ->sourceType == self ::SOURCE_STRING ) {
344
+ $ imageBinary = $ this ->source ;
343
345
} else {
344
346
$ fileHandle = fopen ($ actualSource , 'rb ' , false );
345
347
if ($ fileHandle !== false ) {
@@ -366,33 +368,31 @@ public function getImageStringData($base64 = false)
366
368
/**
367
369
* Check memory image, supported type, image functions, and proportional width/height.
368
370
*
369
- * @param string $source
370
- *
371
371
* @return void
372
372
*
373
373
* @throws \PhpOffice\PhpWord\Exception\InvalidImageException
374
374
* @throws \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException
375
375
*/
376
- private function checkImage ($ source )
376
+ private function checkImage ()
377
377
{
378
- $ this ->setSourceType ($ source );
378
+ $ this ->setSourceType ();
379
379
380
380
// Check image data
381
381
if ($ this ->sourceType == self ::SOURCE_ARCHIVE ) {
382
- $ imageData = $ this ->getArchiveImageSize ($ source );
382
+ $ imageData = $ this ->getArchiveImageSize ($ this -> source );
383
383
} else if ($ this ->sourceType == self ::SOURCE_STRING ) {
384
- $ imageData = $ this ->getStringImageSize ($ source );
384
+ $ imageData = $ this ->getStringImageSize ($ this -> source );
385
385
} else {
386
- $ imageData = @getimagesize ($ source );
386
+ $ imageData = @getimagesize ($ this -> source );
387
387
}
388
388
if (!is_array ($ imageData )) {
389
- throw new InvalidImageException (sprintf ('Invalid image: %s ' , $ source ));
389
+ throw new InvalidImageException (sprintf ('Invalid image: %s ' , $ this -> source ));
390
390
}
391
391
list ($ actualWidth , $ actualHeight , $ imageType ) = $ imageData ;
392
392
393
393
// Check image type support
394
394
$ supportedTypes = array (IMAGETYPE_JPEG , IMAGETYPE_GIF , IMAGETYPE_PNG );
395
- if ($ this ->sourceType != self ::SOURCE_GD ) {
395
+ if ($ this ->sourceType != self ::SOURCE_GD && $ this -> sourceType != self :: SOURCE_STRING ) {
396
396
$ supportedTypes = array_merge ($ supportedTypes , array (IMAGETYPE_BMP , IMAGETYPE_TIFF_II , IMAGETYPE_TIFF_MM ));
397
397
}
398
398
if (!in_array ($ imageType , $ supportedTypes )) {
@@ -408,21 +408,26 @@ private function checkImage($source)
408
408
/**
409
409
* Set source type.
410
410
*
411
- * @param string $source
412
411
* @return void
413
412
*/
414
- private function setSourceType ($ source )
413
+ private function setSourceType ()
415
414
{
416
- if (stripos (strrev ($ source ), strrev ('.php ' )) === 0 ) {
415
+ if (stripos (strrev ($ this -> source ), strrev ('.php ' )) === 0 ) {
417
416
$ this ->memoryImage = true ;
418
417
$ this ->sourceType = self ::SOURCE_GD ;
419
- } elseif (strpos ($ source , 'zip:// ' ) !== false ) {
418
+ } elseif (strpos ($ this -> source , 'zip:// ' ) !== false ) {
420
419
$ this ->memoryImage = false ;
421
420
$ this ->sourceType = self ::SOURCE_ARCHIVE ;
422
- } elseif (filter_var ($ source , FILTER_VALIDATE_URL ) !== false ) {
421
+ } elseif (filter_var ($ this -> source , FILTER_VALIDATE_URL ) !== false ) {
423
422
$ this ->memoryImage = true ;
424
- $ this ->sourceType = self ::SOURCE_GD ;
425
- } elseif (@file_exists ($ source )) {
423
+ if (strpos ($ this ->source , 'https ' ) === 0 ) {
424
+ $ fileContent = file_get_contents ($ this ->source );
425
+ $ this ->source = $ fileContent ;
426
+ $ this ->sourceType = self ::SOURCE_STRING ;
427
+ } else {
428
+ $ this ->sourceType = self ::SOURCE_GD ;
429
+ }
430
+ } elseif (@file_exists ($ this ->source )) {
426
431
$ this ->memoryImage = false ;
427
432
$ this ->sourceType = self ::SOURCE_LOCAL ;
428
433
} else {
@@ -496,18 +501,18 @@ private function setFunctions()
496
501
{
497
502
switch ($ this ->imageType ) {
498
503
case 'image/png ' :
499
- $ this ->imageCreateFunc = 'imagecreatefrompng ' ;
504
+ $ this ->imageCreateFunc = $ this -> sourceType == self :: SOURCE_STRING ? ' imagecreatefromstring ' : 'imagecreatefrompng ' ;
500
505
$ this ->imageFunc = 'imagepng ' ;
501
506
$ this ->imageExtension = 'png ' ;
502
507
break ;
503
508
case 'image/gif ' :
504
- $ this ->imageCreateFunc = 'imagecreatefromgif ' ;
509
+ $ this ->imageCreateFunc = $ this -> sourceType == self :: SOURCE_STRING ? ' imagecreatefromstring ' : 'imagecreatefromgif ' ;
505
510
$ this ->imageFunc = 'imagegif ' ;
506
511
$ this ->imageExtension = 'gif ' ;
507
512
break ;
508
513
case 'image/jpeg ' :
509
514
case 'image/jpg ' :
510
- $ this ->imageCreateFunc = 'imagecreatefromjpeg ' ;
515
+ $ this ->imageCreateFunc = $ this -> sourceType == self :: SOURCE_STRING ? ' imagecreatefromstring ' : 'imagecreatefromjpeg ' ;
511
516
$ this ->imageFunc = 'imagejpeg ' ;
512
517
$ this ->imageExtension = 'jpg ' ;
513
518
break ;
0 commit comments