当前位置:网站首页>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 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
- Time tools
- 浅尝不辄止系列之试试腾讯云的TUIRoom(晚上有约,未完待续...)
- R language ggplot2 visualization: use the ggqqplot function of ggpubr package to visualize the QQ graph (Quantitative quantitative plot)
- pom. Brief introduction of XML configuration file label function
- mysql 的一些重要知识
- sql 常用优化
- Navicat连接2002 - Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘解决
- JVM 类加载机制
- How to buy bank financial products? Do you need a bank card?
猜你喜欢

9 atomic operation class 18 Rohan enhancement
![最多可以参加的会议数目[贪心 + 优先队列]](/img/f3/e8e939e0393efc404cc159d7d33364.png)
最多可以参加的会议数目[贪心 + 优先队列]

PMP對工作有益嗎?怎麼選擇靠譜平臺讓備考更省心省力!!!

Redis——基本使用(key、String、List、Set 、Zset 、Hash、Geo、Bitmap、Hyperloglog、事务 )

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

九章云极DataCanvas公司摘获「第五届数字金融创新大赛」最高荣誉!

CSDN语法说明

编译器优化那些事儿(4):归纳变量

vulnhub之Funfox2

【哲思与实战】程序设计之道
随机推荐
ASP.NET学习& asp‘s one word
How to cooperate among multiple threads
【Auto.js】自动化脚本
Force buckle 599 Minimum index sum of two lists
MIT science and technology review article: AgI hype around Gato and other models may make people ignore the really important issues
Equals method
equals 方法
Ways to improve the utilization of openeuler resources 01: Introduction
Interpretation of transpose convolution theory (input-output size analysis)
关于cv2.dnn.readNetFromONNX(path)就报ERROR during processing node with 3 inputs and 1 outputs的解决过程【独家发布】
A pot of stew, a collection of common commands of NPM and yarn cnpm
Version selection of boot and cloud
pom.xml 配置文件标签:dependencies 和 dependencyManagement 区别
JVM GC garbage collection brief
力扣674. 最长连续递增序列
Openeuler prize catching activities, to participate in?
Force buckle 674 Longest continuous increasing sequence
最多可以参加的会议数目[贪心 + 优先队列]
vulnhub之Funfox2
干货分享|DevExpress v22.1原版帮助文档下载集合