Skip to content

Commit

Permalink
Merge pull request #353 from thecodingmachine/imagecreatefromstring
Browse files Browse the repository at this point in the history
FEATURE: added back imagecreatefromstring
  • Loading branch information
Kharhamel authored May 2, 2022
2 parents 9cdf226 + 548ea68 commit b206c26
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions generated/functionsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@
'imagecreatefromgif',
'imagecreatefromjpeg',
'imagecreatefrompng',
'imagecreatefromstring',
'imagecreatefromtga',
'imagecreatefromwbmp',
'imagecreatefromwebp',
Expand Down
24 changes: 24 additions & 0 deletions generated/image.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion generator/src/DocPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions generator/tests/DocPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
}

Expand Down
1 change: 1 addition & 0 deletions rector-migrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit b206c26

Please sign in to comment.