首页
下载
文档
社区
视频
捐赠
源代码
赞助商
AOT 编译器
AI 助理
商业产品
PHP AOT 原生编译器
Swoole-Compiler 代码加密器
CRMEB 新零售社交电商系统
登录
注册
全部
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
发表新帖
swoole http server 如何支持gd库的imagejpeg,直接输出图片给浏览器
### swoole http server 如何支持gd库的imagejpeg,直接输出图片给浏览器,目前实现方法是先保存为文件,再读出响应给浏览器。 ### Swoole v4.5,PHP v7.4,ubuntu 1604 ### 相关代码 <?php $http = new Swoole\Http\Server("0.0.0.0", 9501); $http->on('request', function ($request, $response) { $image_quality=98; $browser=1; $file ="jj.jpeg"; $pic_im = imagecreatefromjpeg($file); $file_name="temp/".md5(rand(0,1000000000000000)).".jpeg"; imagejpeg($pic_im,$file_name,$image_quality); $response->header('content-type', 'image/jpeg'); $response->sendfile($file_name); // Free up memory imagedestroy($pic_im); }); $http->start(); ### 直接输出图片给浏览器的方法
发布于6年前 · 5 次浏览 · 来自
提问
梅港浪人
### swoole http server 如何支持gd库的imagejpeg,直接输出图片给浏览器,目前实现方法是先保存为文件,再读出响应给浏览器。 ### Swoole v4.5,PHP v7.4,ubuntu 1604 ### 相关代码 <?php $http = new Swoole\Http\Server("0.0.0.0", 9501); $http->on('request', function ($request, $response) { $image_quality=98; $browser=1; $file ="jj.jpeg"; $pic_im = imagecreatefromjpeg($file); $file_name="temp/".md5(rand(0,1000000000000000)).".jpeg"; imagejpeg($pic_im,$file_name,$image_quality); $response->header('content-type', 'image/jpeg'); $response->sendfile($file_name); // Free up memory imagedestroy($pic_im); }); $http->start(); ### 直接输出图片给浏览器的方法
赞
0
收藏
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
登录
后参与评论
评论
2020-05-07
鲁飞
```php $http = new Swoole\Http\Server("0.0.0.0", 9501); $http->on("request", function ($request, $response) { $image_quality = 98; $file = "33931153.jpeg"; $pic_im = imagecreatefromjpeg($file); $response->header("content-type", "image/jpeg"); ob_start(); imagejpeg($pic_im, NULL, $image_quality); $content = ob_get_clean(); $response->end($content); imagedestroy($pic_im); }); $http->start(); ```
赞
2
回复