php – 为什么有imageCreateFrom *如果有imageCreateFromString?

我真的不明白为什么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行)轻微的好处.

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...