我真的不明白为什么GD有不同的功能来加载图像,如:
imagecreatefromjpeg()
imagecreatefrompng()
imagecreatefromgif()
Run Code Online (Sandbox Code Playgroud)
虽然图像是字符串,但只有一个功能?
imagecreatefromstring()
Run Code Online (Sandbox Code Playgroud)
实际上,将图像读入字符串并将其传递给函数会更好,例如:
$imgBlob = file_get_contents($imagePath);
imagecreatefromstring($imageBlob);
unset($imgBlob); //> Free memory, but I am not interested in memory consumpation
Run Code Online (Sandbox Code Playgroud)
?或者我错过了什么?这可能会导致新用户的混淆
也许他们只是忘了创建一个函数imageCreateFromFile()
?
PS.当然我对使用该file_get_contents
方法的内存消耗不感兴趣
Cha*_*ser 10
imagecreatefromstring()
对传递的图像类型运行一个开关,检查您的系统是否支持该图像类型,然后实际运行正确的imagecreatefrom*
函数.
您可以查看源代码以查看:https://github.com/php/php-src/blob/master/ext/gd/gd.c? source = cc(第2280行为功能,第2301行,其中它打开图像类型并调用正确的函数).
所以,该imagecreatefromstring()
函数实际上只是一个帮助包装器._php_image_type
如果调用实际的图像类型函数,您将从未运行(第2217行)中获得非常小的好处.
归档时间: |
|
查看次数: |
7466 次 |
最近记录: |