在php中获取相同大小的图像 [英] Get images within same size in php

查看:69
本文介绍了在php中获取相同大小的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个用于获取Instagram标签图像作为输出的应用程序.我可以加载图像.但是我需要获得相同尺寸的图像.有人帮我解决这个问题吗?

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?

这是代码...

  <?php
    function scrape_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 src="'.$latest_array['thumbnail_src'].'">'; 
            array_push($image_array, $image_data);
        }


        foreach ($image_array as $image) {
            echo $image;
    }
      ?>

推荐答案

以下代码将图像调整为所需大小.

The following code will resize the images to the size you want.

<?php
$height = 150;
$width = 150;
    function scrape_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_array as $image) {
                echo $image;
            }
?>

这篇关于在php中获取相同大小的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆