diff --git a/generated/functionsList.php b/generated/functionsList.php index b1c28d6f..3c537d1f 100644 --- a/generated/functionsList.php +++ b/generated/functionsList.php @@ -337,6 +337,7 @@ 'imagecreatefromgif', 'imagecreatefromjpeg', 'imagecreatefrompng', + 'imagecreatefromstring', 'imagecreatefromtga', 'imagecreatefromwbmp', 'imagecreatefromwebp', diff --git a/generated/image.php b/generated/image.php index 91342964..639cf16c 100644 --- a/generated/image.php +++ b/generated/image.php @@ -911,6 +911,30 @@ function imagecreatefrompng(string $filename) } +/** + * imagecreatefromstring returns an image identifier + * representing the image obtained from the given data. + * These types will be automatically detected if your build of PHP supports + * them: JPEG, PNG, GIF, BMP, WBMP, GD2, and WEBP. + * + * @param string $data A string containing the image data. + * @return resource An image object will be returned on success. FALSE is returned if + * the image type is unsupported, the data is not in a recognised format, + * or the image is corrupt and cannot be loaded. + * @throws ImageException + * + */ +function imagecreatefromstring(string $data) +{ + error_clear_last(); + $result = \imagecreatefromstring($data); + if ($result === false) { + throw ImageException::createFromPhpError(); + } + return $result; +} + + /** * imagecreatefromtga returns an image object * representing the image obtained from the given filename. diff --git a/generator/src/DocPage.php b/generator/src/DocPage.php index 9af68225..9354428d 100644 --- a/generator/src/DocPage.php +++ b/generator/src/DocPage.php @@ -125,7 +125,7 @@ public function detectFalsyFunction(): bool } //used to detect imagecreatefromstring - if (preg_match('/If the arguments are invalid, the function returns &false;/m', $returnValuesSection)) { + if (preg_match('/&false; is returned if\s+the image type is unsupported, the data is not in a recognised format,\s+or the image is corrupt and cannot be loaded/m', $returnValuesSection)) { return true; } diff --git a/generator/tests/DocPageTest.php b/generator/tests/DocPageTest.php index 5f449c41..6a2ab878 100644 --- a/generator/tests/DocPageTest.php +++ b/generator/tests/DocPageTest.php @@ -21,6 +21,7 @@ public function testDetectFalsyFunction() $classImplement = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/spl/functions/class-implements.xml'); $getHeaders = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/url/functions/get-headers.xml'); $gzopen = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/zlib/functions/gzopen.xml'); + $fopen = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/image/functions/imagecreatefromstring.xml'); //$ldapSearch = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/ldap/functions/ldap-search.xml'); $this->assertTrue($pregMatch->detectFalsyFunction()); @@ -36,6 +37,7 @@ public function testDetectFalsyFunction() $this->assertTrue($classImplement->detectFalsyFunction()); $this->assertTrue($getHeaders->detectFalsyFunction()); $this->assertTrue($gzopen->detectFalsyFunction()); + $this->assertTrue($fopen->detectFalsyFunction()); //$this->assertTrue($ldapSearch->detectFalsyFunction()); } diff --git a/rector-migrate.php b/rector-migrate.php index e8c0da9f..efa2a286 100644 --- a/rector-migrate.php +++ b/rector-migrate.php @@ -347,6 +347,7 @@ 'imagecreatefromgif' => 'Safe\imagecreatefromgif', 'imagecreatefromjpeg' => 'Safe\imagecreatefromjpeg', 'imagecreatefrompng' => 'Safe\imagecreatefrompng', + 'imagecreatefromstring' => 'Safe\imagecreatefromstring', 'imagecreatefromtga' => 'Safe\imagecreatefromtga', 'imagecreatefromwbmp' => 'Safe\imagecreatefromwbmp', 'imagecreatefromwebp' => 'Safe\imagecreatefromwebp',