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

PHP method of obtaining image information

2022-07-07 20:09:00 salestina

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 :

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 :

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

原网站

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