@@ -340,6 +340,8 @@ public function getImageStringData($base64 = false)
340340 call_user_func ($ this ->imageFunc , $ imageResource );
341341 $ imageBinary = ob_get_contents ();
342342 ob_end_clean ();
343+ } elseif ($ this ->sourceType == self ::SOURCE_STRING ) {
344+ $ imageBinary = $ this ->source ;
343345 } else {
344346 $ fileHandle = fopen ($ actualSource , 'rb ' , false );
345347 if ($ fileHandle !== false ) {
@@ -366,33 +368,31 @@ public function getImageStringData($base64 = false)
366368 /**
367369 * Check memory image, supported type, image functions, and proportional width/height.
368370 *
369- * @param string $source
370- *
371371 * @return void
372372 *
373373 * @throws \PhpOffice\PhpWord\Exception\InvalidImageException
374374 * @throws \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException
375375 */
376- private function checkImage ($ source )
376+ private function checkImage ()
377377 {
378- $ this ->setSourceType ($ source );
378+ $ this ->setSourceType ();
379379
380380 // Check image data
381381 if ($ this ->sourceType == self ::SOURCE_ARCHIVE ) {
382- $ imageData = $ this ->getArchiveImageSize ($ source );
382+ $ imageData = $ this ->getArchiveImageSize ($ this -> source );
383383 } else if ($ this ->sourceType == self ::SOURCE_STRING ) {
384- $ imageData = $ this ->getStringImageSize ($ source );
384+ $ imageData = $ this ->getStringImageSize ($ this -> source );
385385 } else {
386- $ imageData = @getimagesize ($ source );
386+ $ imageData = @getimagesize ($ this -> source );
387387 }
388388 if (!is_array ($ imageData )) {
389- throw new InvalidImageException (sprintf ('Invalid image: %s ' , $ source ));
389+ throw new InvalidImageException (sprintf ('Invalid image: %s ' , $ this -> source ));
390390 }
391391 list ($ actualWidth , $ actualHeight , $ imageType ) = $ imageData ;
392392
393393 // Check image type support
394394 $ 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 ) {
396396 $ supportedTypes = array_merge ($ supportedTypes , array (IMAGETYPE_BMP , IMAGETYPE_TIFF_II , IMAGETYPE_TIFF_MM ));
397397 }
398398 if (!in_array ($ imageType , $ supportedTypes )) {
@@ -408,21 +408,26 @@ private function checkImage($source)
408408 /**
409409 * Set source type.
410410 *
411- * @param string $source
412411 * @return void
413412 */
414- private function setSourceType ($ source )
413+ private function setSourceType ()
415414 {
416- if (stripos (strrev ($ source ), strrev ('.php ' )) === 0 ) {
415+ if (stripos (strrev ($ this -> source ), strrev ('.php ' )) === 0 ) {
417416 $ this ->memoryImage = true ;
418417 $ this ->sourceType = self ::SOURCE_GD ;
419- } elseif (strpos ($ source , 'zip:// ' ) !== false ) {
418+ } elseif (strpos ($ this -> source , 'zip:// ' ) !== false ) {
420419 $ this ->memoryImage = false ;
421420 $ this ->sourceType = self ::SOURCE_ARCHIVE ;
422- } elseif (filter_var ($ source , FILTER_VALIDATE_URL ) !== false ) {
421+ } elseif (filter_var ($ this -> source , FILTER_VALIDATE_URL ) !== false ) {
423422 $ 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 )) {
426431 $ this ->memoryImage = false ;
427432 $ this ->sourceType = self ::SOURCE_LOCAL ;
428433 } else {
@@ -496,18 +501,18 @@ private function setFunctions()
496501 {
497502 switch ($ this ->imageType ) {
498503 case 'image/png ' :
499- $ this ->imageCreateFunc = 'imagecreatefrompng ' ;
504+ $ this ->imageCreateFunc = $ this -> sourceType == self :: SOURCE_STRING ? ' imagecreatefromstring ' : 'imagecreatefrompng ' ;
500505 $ this ->imageFunc = 'imagepng ' ;
501506 $ this ->imageExtension = 'png ' ;
502507 break ;
503508 case 'image/gif ' :
504- $ this ->imageCreateFunc = 'imagecreatefromgif ' ;
509+ $ this ->imageCreateFunc = $ this -> sourceType == self :: SOURCE_STRING ? ' imagecreatefromstring ' : 'imagecreatefromgif ' ;
505510 $ this ->imageFunc = 'imagegif ' ;
506511 $ this ->imageExtension = 'gif ' ;
507512 break ;
508513 case 'image/jpeg ' :
509514 case 'image/jpg ' :
510- $ this ->imageCreateFunc = 'imagecreatefromjpeg ' ;
515+ $ this ->imageCreateFunc = $ this -> sourceType == self :: SOURCE_STRING ? ' imagecreatefromstring ' : 'imagecreatefromjpeg ' ;
511516 $ this ->imageFunc = 'imagejpeg ' ;
512517 $ this ->imageExtension = 'jpg ' ;
513518 break ;
0 commit comments