我真的不明白为什么GD具有不同的加载图像的功能,如:
imagecreatefromjpeg() imagecreatefrompng() imagecreatefromgif()
如果图像是字符串,则有单个功能?
imagecreatefromstring()
事实上,将图像读入字符串并将其传递给函数更好,类似于:
$imgBlob = file_get_contents($imagePath); imagecreatefromstring($imageBlob); unset($imgBlob); //> Free memory,but I am not interested in memory consumpation
?还是我错过了什么?这可能会给新用户带来潜在的混乱
也许他们只是忘了创建一个函数imageCreateFromFile()?
PS.当然,我对使用file_get_contents方法的内存消耗不感兴趣
imagecreatefromstring()针对传递的图像类型运行开关,检查您的系统是否支持该图像类型,然后实际运行正确的imagecreatefrom *函数.
您可以查看源代码以查看:https://github.com/php/php-src/blob/master/ext/gd/gd.c?source=cc(第2280行功能,第2301行,其中切换图像类型并调用正确的功能).
所以,imagecreatefromstring()函数实际上只是一个辅助包装.如果您调用实际的图像类型功能,您将不会运行_PHP_image_type(第2217行)轻微的好处.