当前位置:网站首页>php 获取图片信息的方法
php 获取图片信息的方法
2022-07-07 21:43:00 【游戏编程】
想通过php获取图片的宽高,下面是两种方法,可以作为参考。
方法一:
ini_set('user_agent','Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 6.0)');$thumb_url="https://dss0.bdstatic.com/-0U0bXSm1A5BphGlnYG/tam-ogel/2dbeac414fc1ee690d00c764c89a187e_121_121.png";$imageInfo=getimagesize($thumb_url);print_r($imageInfo);
打印结果为:

方法二:
$refer="https://dss0.bdstatic.com";$option=array('http'=>array('header'=>"Referer: {$refer}"));$context=stream_context_create($option);//创建资源流上下文$thumb_url="https://dss0.bdstatic.com/-0U0bXSm1A5BphGlnYG/tam-ogel/2dbeac414fc1ee690d00c764c89a187e_121_121.png";$file_contents = file_get_contents($thumb_url,false, $context);//将整个文件读入一个字符串$thumb_size = getimagesizefromstring($file_contents);//从字符串中获取图像尺寸信息print_r($thumb_size);
打印结果为:

两种方法都可以获取图片的信息,可自行选择使用哪一种。
作者:salestina
游戏编程,一个游戏开发收藏夹~
如果图片长时间未显示,请使用Chrome内核浏览器。
边栏推荐
- Win11如何解禁键盘?Win11解禁键盘的方法
- Xcode modifies the default background image of launchscreen and still displays the original image
- 海外代理推荐
- PDF文档签名指南
- Vs custom template - take the custom class template as an example
- Interview question 01.02 Determine whether it is character rearrangement - auxiliary array algorithm
- UWA问答精选
- Typeorm automatically generates entity classes
- Jerry's initiation of ear pairing, reconnection, and opening of discoverable and connectable cyclic functions [chapter]
- DBSync新增对MongoDB、ES的支持
猜你喜欢
Jerry's test box configuration channel [chapter]
NVR hard disk video recorder is connected to easycvr through the national standard gb28181 protocol. What is the reason why the device channel information is not displayed?
Solve the problem of uni in uni app Request sent a post request without response.
648. Word replacement
vite Unrestricted file system access to
[azure microservice service fabric] start the performance monitor in the SF node and set the method of capturing the process
谈谈制造企业如何制定敏捷的数字化转型策略
Jerry's about TWS pairing mode configuration [chapter]
使用 CustomPaint 绘制基本图形
Cv2.resize function reports an error: error: (-215:assertion failed) func= 0 in function ‘cv::hal::resize‘
随机推荐
OpeGL personal notes - lights
Ueeditor custom display insert code
#DAYU200体验官#MPPT光伏发电项目 DAYU200、Hi3861、华为云IotDA
What if the win11u disk does not display? Solution to failure of win11 plug-in USB flash disk
Win11U盘不显示怎么办?Win11插U盘没反应的解决方法
Jerry's power on automatic pairing [chapter]
Node:504 error reporting
IP网络主动测评系统——X-Vision
Revit secondary development - link file collision detection
Use json Stringify() to realize deep copy, be careful, there may be a huge hole
vite Unrestricted file system access to
Jerry's about TWS pairing mode configuration [chapter]
[azure microservice service fabric] how to transfer seed nodes in the service fabric cluster
Write in front -- Talking about program development
Implementation method of data platform landing
[open source] Net ORM accessing Firebird database
Jerry's configuration of TWS cross pairing [article]
Matplotlib drawing interface settings
Time standard library
The function is really powerful!