Get Images Within Same Size In Php
I created a application for get Instagram tags images as a output. I can load the images. But I need to get images within same size. Anyone help me to solve this? Here is the code.
Solution 1:
you can do something like this :
<?php$tag = 'savesripada';
$results_array = scrape_insta_hash($tag);
$image_array = array_filter(
$results_array['entry_data']['TagPage'][0]['graphql']['hashtag']['edge_hashtag_to_media']['edges'],
function($item) {
$size = $item['node']['dimensions']; // example : [height: 810, width: 1080]return$size['height'] === '130' && $size['width'] === '150'; // Adjust your condition if you want another metrix
});
var_dump($image_array); // Will print image with exactly 150*130
Here i use array_filter
to search and pick up image who only have height == 130 and width == 150.
Solution 2:
The following code will resize the images to the size you want.
<?php$height = 150;
$width = 150;
functionscrape_insta_hash($tag) {
$insta_source =
file_get_contents('https://www.instagram.com/explore/tags/'.$tag.'/');
$shards = explode('window._sharedData = ', $insta_source);
$insta_json = explode(';</script>', $shards[1]);
$insta_array = json_decode($insta_json[0], TRUE);
return$insta_array;
}
$tag = 'savesripada';
$results_array = scrape_insta_hash($tag);
$limit = 15;
$image_array= array();
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="'.$height.'" width="'.$width.'" src="'.$latest_array['thumbnail_src'].'">';
array_push($image_array, $image_data);
}
foreach ($image_arrayas$image) {
echo$image;
}
?>
Post a Comment for "Get Images Within Same Size In Php"