当前位置:网站首页>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内核浏览器。
边栏推荐
- The essence of analog Servlet
- L2: current situation, prospects and pain points of ZK Rollup
- [开源] .Net ORM 访问 Firebird 数据库
- The function is really powerful!
- Revit secondary development - collision detection
- Programming mode - table driven programming
- 大数据开源项目,一站式全自动化全生命周期运维管家ChengYing(承影)走向何方?
- Solve the problem of uni in uni app Request sent a post request without response.
- 【Azure微服务 Service Fabric 】因证书过期导致Service Fabric集群挂掉(升级无法完成,节点不可用)
- MIT6.S081-Lab9 FS [2021Fall]
猜你喜欢

Pdf document signature Guide

Embedded development: how to choose the right RTOS for the project?

OpenGL configuration vs2019

Add get disabled for RC form

Matplotlib drawing interface settings

. Net automapper use

The whole network "chases" Zhong Xuegao

ByteDance Android interview, summary of knowledge points + analysis of interview questions
![[开源] .Net ORM 访问 Firebird 数据库](/img/a2/4eff4f0af53bf3b9839a73019a212f.png)
[开源] .Net ORM 访问 Firebird 数据库

An in-depth understanding of fp/fn/precision/recall
随机推荐
[colmap] sparse reconstruction is converted to mvsnet format input
Which futures company is the safest to open a futures account?
Build your own website (18)
[JDBC Part 1] overview, get connection, CRUD
TCP/IP 协议栈
How to choose the appropriate automated testing tools?
OpenGL configuration vs2019
MIT6.S081-Lab9 FS [2021Fall]
Interview question 01.02 Determine whether it is character rearrangement - auxiliary array algorithm
Antd date component appears in English
Paint basic graphics with custompaint
How to make agile digital transformation strategy for manufacturing enterprises
The strongest installation of the twin tower model, Google is playing "antique" again?
[open source] Net ORM accessing Firebird database
Add get disabled for RC form
Welcome to CSDN markdown editor
Customer case | China law network, through observing the cloud, greatly shortens the time of fault location
Tcp/ip protocol stack
The function is really powerful!
Jerry's initiation of ear pairing, reconnection, and opening of discoverable and connectable cyclic functions [chapter]