当前位置:网站首页>PHP method of obtaining image information

PHP method of obtaining image information

2022-07-07 22:30:00 Game programming

Want to pass php Gets the width and height of the image , Here are two ways , As a reference .
Method 1 :

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);

The result is :

php Methods of obtaining picture information - The first 1 Zhang

Method 2 :

$refer="https://dss0.bdstatic.com";$option=array('http'=>array('header'=>"Referer: {$refer}"));$context=stream_context_create($option);// Create a resource flow context $thumb_url="https://dss0.bdstatic.com/-0U0bXSm1A5BphGlnYG/tam-ogel/2dbeac414fc1ee690d00c764c89a187e_121_121.png";$file_contents = file_get_contents($thumb_url,false, $context);// Read the entire file into a string $thumb_size = getimagesizefromstring($file_contents);// Get image size information from string print_r($thumb_size);

The result is :

php Methods of obtaining picture information - The first 2 Zhang

Both methods can obtain the information of pictures , You can choose which one to use .
author :salestina

Game programming , A game development favorite ~

If the picture is not displayed for a long time , Please use Chrome Kernel browser .

原网站

版权声明
本文为[Game programming]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071943571299.html