Skip to content

Commit b206c26

Browse files
authored
Merge pull request #353 from thecodingmachine/imagecreatefromstring
FEATURE: added back imagecreatefromstring
2 parents 9cdf226 + 548ea68 commit b206c26

File tree

5 files changed

+29
-1
lines changed

5 files changed

+29
-1
lines changed

generated/functionsList.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@
337337
'imagecreatefromgif',
338338
'imagecreatefromjpeg',
339339
'imagecreatefrompng',
340+
'imagecreatefromstring',
340341
'imagecreatefromtga',
341342
'imagecreatefromwbmp',
342343
'imagecreatefromwebp',

generated/image.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,30 @@ function imagecreatefrompng(string $filename)
911911
}
912912

913913

914+
/**
915+
* imagecreatefromstring returns an image identifier
916+
* representing the image obtained from the given data.
917+
* These types will be automatically detected if your build of PHP supports
918+
* them: JPEG, PNG, GIF, BMP, WBMP, GD2, and WEBP.
919+
*
920+
* @param string $data A string containing the image data.
921+
* @return resource An image object will be returned on success. FALSE is returned if
922+
* the image type is unsupported, the data is not in a recognised format,
923+
* or the image is corrupt and cannot be loaded.
924+
* @throws ImageException
925+
*
926+
*/
927+
function imagecreatefromstring(string $data)
928+
{
929+
error_clear_last();
930+
$result = \imagecreatefromstring($data);
931+
if ($result === false) {
932+
throw ImageException::createFromPhpError();
933+
}
934+
return $result;
935+
}
936+
937+
914938
/**
915939
* imagecreatefromtga returns an image object
916940
* representing the image obtained from the given filename.

generator/src/DocPage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function detectFalsyFunction(): bool
125125
}
126126

127127
//used to detect imagecreatefromstring
128-
if (preg_match('/If the arguments are invalid, the function returns &false;/m', $returnValuesSection)) {
128+
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)) {
129129
return true;
130130
}
131131

generator/tests/DocPageTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public function testDetectFalsyFunction()
2121
$classImplement = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/spl/functions/class-implements.xml');
2222
$getHeaders = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/url/functions/get-headers.xml');
2323
$gzopen = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/zlib/functions/gzopen.xml');
24+
$fopen = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/image/functions/imagecreatefromstring.xml');
2425
//$ldapSearch = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/ldap/functions/ldap-search.xml');
2526

2627
$this->assertTrue($pregMatch->detectFalsyFunction());
@@ -36,6 +37,7 @@ public function testDetectFalsyFunction()
3637
$this->assertTrue($classImplement->detectFalsyFunction());
3738
$this->assertTrue($getHeaders->detectFalsyFunction());
3839
$this->assertTrue($gzopen->detectFalsyFunction());
40+
$this->assertTrue($fopen->detectFalsyFunction());
3941
//$this->assertTrue($ldapSearch->detectFalsyFunction());
4042
}
4143

rector-migrate.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@
347347
'imagecreatefromgif' => 'Safe\imagecreatefromgif',
348348
'imagecreatefromjpeg' => 'Safe\imagecreatefromjpeg',
349349
'imagecreatefrompng' => 'Safe\imagecreatefrompng',
350+
'imagecreatefromstring' => 'Safe\imagecreatefromstring',
350351
'imagecreatefromtga' => 'Safe\imagecreatefromtga',
351352
'imagecreatefromwbmp' => 'Safe\imagecreatefromwbmp',
352353
'imagecreatefromwebp' => 'Safe\imagecreatefromwebp',

0 commit comments

Comments
 (0)