当前位置:网站首页>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);
打印结果为:
两种方法都可以获取图片的信息,可自行选择使用哪一种。
边栏推荐
- ASP. Net gymnasium integrated member management system source code, free sharing
- ASP. Net learning & ASP's one word
- openEuler 有奖捉虫活动,来参与一下?
- 九章云极DataCanvas公司摘获「第五届数字金融创新大赛」最高荣誉!
- YoloV6:YoloV6+Win10---训练自己得数据集
- tp6 实现佣金排行榜
- [sword finger offer] sword finger offer II 012 The sum of left and right subarrays is equal
- Force buckle 88 Merge two ordered arrays
- Visual Studio 插件之CodeMaid自动整理代码
- Force buckle 1037 Effective boomerang
猜你喜欢
Navicat连接2002 - Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘解决
Cloud component development and upgrading
Vulnhub tre1
Compiler optimization (4): inductive variables
开源重器!九章云极DataCanvas公司YLearn因果学习开源项目即将发布!
Force buckle 2319 Judge whether the matrix is an X matrix
LeetCode_7_5
Leetcode force buckle (Sword finger offer 36-39) 36 Binary search tree and bidirectional linked list 37 Serialize binary tree 38 Arrangement of strings 39 Numbers that appear more than half of the tim
华南X99平台打鸡血教程
【STL】vector
随机推荐
力扣 1037.有效的回旋镖
力扣 88.合并两个有序数组
Navicat连接2002 - Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘解决
线性基
多个线程之间如何协同
The project manager's "eight interview questions" is equal to a meeting
vulnhub之school 1
Flink并行度和Slot详解
Force buckle 88 Merge two ordered arrays
力扣 599. 两个列表的最小索引总和
Force buckle 674 Longest continuous increasing sequence
Is PMP beneficial to work? How to choose a reliable platform to make it easier to prepare for the exam!!!
Open source heavy ware! Chapter 9 the open source project of ylarn causal learning of Yunji datacanvas company will be released soon!
浅尝不辄止系列之试试腾讯云的TUIRoom(晚上有约,未完待续...)
力扣 1232.缀点成线
tp6 实现佣金排行榜
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 资源利用率提升之道 01:概论
Automatic classification of defective photovoltaic module cells in electroluminescence images-论文阅读笔记
力扣599. 两个列表的最小索引总和