php - 显示特定尺寸的图像
问题描述
我在 php.ini 中显示特定大小的图像时遇到问题。在这里,我使用了 foreach 循环。任何人都可以帮我解决这个问题。
这是代码,
<?php
function scrape_insta_hash($tag) {
$insta_source = file_get_contents('https://www.instagram.com/explore/tags/'.$tag.'/'); // instagrame tag url
$shards = explode('window._sharedData = ', $insta_source);
$insta_json = explode(';</script>', $shards[1]);
$insta_array = json_decode($insta_json[0], TRUE);
return $insta_array; // this return a lot things print it and see what else you need
}
$tag = 'paris'; // tag for which ou want images
$results_array = scrape_insta_hash($tag);
//$limit = 7;
$limit = 15; // provide the limit thats important because one page only give some images.
$image_array= array(); // array to store images.
for ($i=0; $i < $limit; $i++) {
$latest_array = $results_array['entry_data']['TagPage'][0]['graphql']['hashtag']['edge_hashtag_to_media']['edges'][$i]['node'];
$image_data = '<img src="'.$latest_array['thumbnail_src'].'">'; // thumbnail and same sizes
//$image_data = '<img src="'.$latest_array['display_src'].'">'; actual image and different sizes
array_push($image_array, $image_data);
}
foreach ($image_array as $image) {
echo $image;
}
?>
解决方案
使用您想要的图像高度和宽度属性更改您的 for 循环
for ($i=0; $i < $limit; $i++) {
$latest_array = $results_array['entry_data']['TagPage'][0]['graphql']['hashtag']['edge_hashtag_to_media']['edges'][$i]['node'];
$image_data = '<img height="150" width="150" src="'.$latest_array['thumbnail_src'].'">'; // thumbnail and same sizes
//$image_data = '<img src="'.$latest_array['display_src'].'">'; actual image and different sizes
array_push($image_array, $image_data);
}
推荐阅读
- amazon-web-services - AWS 通知我,我的访问和私钥是公开可用的
- facebook - Instagram API - 拉入单个用户提要的最简单方法
- python - 如何根据文件中的特定列对 IPv6 地址进行排序?
- sql - 为什么 count(case date) 也计算空情况?
- python - 网络爬虫可以区分编码吗?
- php - 无法将数据插入数据库laravel ajax
- python - zmq.Context() 在启动后挂起几分钟
- sql - Oracle 11g 中如何将动态列转换为行?
- sql - 如何在我的 ms 访问代码中修复此编译错误?
- java - 相同的appium代码不适用于相同的应用程序