当前位置:网站首页>php 获取图片信息的方法
php 获取图片信息的方法
2022-07-07 18:04:00 【salestina】
想通过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);
打印结果为:
两种方法都可以获取图片的信息,可自行选择使用哪一种。
边栏推荐
- Mysql, sqlserver Oracle database connection mode
- Training IX basic configuration of network services
- 力扣 1790. 仅执行一次字符串交换能否使两个字符串相等
- My creation anniversary
- Interpretation of transpose convolution theory (input-output size analysis)
- Le PGR est - il utile au travail? Comment choisir une plate - forme fiable pour économiser le cœur et la main - d'œuvre lors de la préparation de l'examen!!!
- Openeuler prize catching activities, to participate in?
- Nunjuks template engine
- Semantic SLAM源码解析
- 让这个 CRMEB 单商户微信商城系统火起来,太好用了!
猜你喜欢
使用高斯Redis实现二级索引
PMP對工作有益嗎?怎麼選擇靠譜平臺讓備考更省心省力!!!
PMP practice once a day | don't get lost in the exam -7.7
9 atomic operation class 18 Rohan enhancement
Introduction to bit operation
Le PGR est - il utile au travail? Comment choisir une plate - forme fiable pour économiser le cœur et la main - d'œuvre lors de la préparation de l'examen!!!
数据孤岛是企业数字化转型遇到的第一道险关
Some important knowledge of MySQL
CSDN syntax description
vulnhub之Funfox2
随机推荐
The project manager's "eight interview questions" is equal to a meeting
openEuler 有奖捉虫活动,来参与一下?
RESTAPI 版本控制策略【eolink 翻译】
Is PMP beneficial to work? How to choose a reliable platform to make it easier to prepare for the exam!!!
【STL】vector
Boot 和 Cloud 的版本选型
CSDN syntax description
tp6 实现佣金排行榜
国家网信办公布《数据出境安全评估办法》:累计向境外提供10万人信息需申报
IP 工具类
Force buckle 2319 Judge whether the matrix is an X matrix
JVM class loading mechanism
Version selection of boot and cloud
Some arrangements about oneself
Force buckle 643 Subarray maximum average I
力扣 599. 两个列表的最小索引总和
The boundary of Bi: what is bi not suitable for? Master data, Martech? How to expand?
mysql 的一些重要知识
ASP. Net kindergarten chain management system source code
Force buckle 88 Merge two ordered arrays