当前位置:网站首页>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);打印结果为:

两种方法都可以获取图片的信息,可自行选择使用哪一种。
边栏推荐
- LeetCode_ 7_ five
- Force buckle 1790 Can two strings be equal by performing string exchange only once
- 一锅乱炖,npm、yarn cnpm常用命令合集
- Ways to improve the utilization of openeuler resources 01: Introduction
- 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!!!
- pom.xml 配置文件标签:dependencies 和 dependencyManagement 区别
- 力扣 2315.统计星号
- Force buckle 2319 Judge whether the matrix is an X matrix
- The state cyberspace Office released the measures for data exit security assessment: 100000 information provided overseas needs to be declared
- 【Auto.js】自动化脚本
猜你喜欢
Make this crmeb single merchant wechat mall system popular, so easy to use!

Data island is the first danger encountered by enterprises in their digital transformation

力扣 2319. 判断矩阵是否是一个 X 矩阵

PMP practice once a day | don't get lost in the exam -7.7

8 CAS

Implement secondary index with Gaussian redis

Cloud component development and upgrading

数据孤岛是企业数字化转型遇到的第一道险关

论文解读(ValidUtil)《Rethinking the Setting of Semi-supervised Learning on Graphs》

vulnhub之Funfox2
随机推荐
Mysql, sqlserver Oracle database connection mode
CSDN语法说明
TS快速入门-泛型
Force buckle 643 Subarray maximum average I
九章云极DataCanvas公司摘获「第五届数字金融创新大赛」最高荣誉!
Force buckle 599 Minimum index sum of two lists
LeetCode_7_5
Some arrangements about oneself
CIS芯片测试到底怎么测?
Automatic classification of defective photovoltaic module cells in electroluminescence images-論文閱讀筆記
九章云极DataCanvas公司获评36氪「最受投资人关注的硬核科技企业」
一锅乱炖,npm、yarn cnpm常用命令合集
开源OA开发平台:合同管理使用手册
Equals method
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!!!
Boot 和 Cloud 的版本选型
SQL common optimization
Cuda版本不一致,编译apex报错
mysql 的一些重要知识
9 atomic operation class 18 Rohan enhancement