How to get cropped image from Instagram API?

I am currently getting this image:

https://scontent.cdninstagram.com/hphotos-xtp1/t51.2885-15/s320x320/e35/11950569_428157634035762_1539002513_n.jpg

enter image description here

but I would like to get this version of the image:

https://igcdn-photos-b-a.akamaihd.net/hphotos-ak-xfp1/t51.2885-15/e35/c238.0.603.603/11856567_458440314342209_1536381871_n.jpg

img2

This is how I create the API URL:

var apiEndpoint = "https://api.instagram.com/v1";

    function composeRequestURL() {

        var url = apiEndpoint,
            params = {};

        if (settings.next_url != null) {
            return settings.next_url;
        }

        if (settings.hash != null) {
            url += "/tags/" + settings.hash + "/media/recent";
        }
        else if (settings.search != null) {
            url += "/media/search";
            params.lat = settings.search.lat;
            params.lng = settings.search.lng;
            settings.search.max_timestamp != null && (params.max_timestamp = settings.search.max_timestamp);
            settings.search.min_timestamp != null && (params.min_timestamp = settings.search.min_timestamp);
            settings.search.distance != null && (params.distance = settings.search.distance);
        }
        else if (settings.userId != null) {
            url += "/users/" + settings.userId + "/media/recent";
        }
        else if (settings.locationId != null) {
            url += "/locations/" + settings.locationId + "/media/recent";
        }
        else {
            url += "/media/popular";
        }

        settings.accessToken != null && (params.access_token = settings.accessToken);
        settings.clientId != null && (params.client_id = settings.clientId);
        settings.minId != null && (params.min_id = settings.minId);
        settings.maxId != null && (params.max_id = settings.maxId);
        settings.show != null && (params.count = settings.show);

        url += "?" + $.param(params)

        return url;
    }

Is there any suggestion to get this cropped image? Many thanks.

+4
source share
1 answer

Yes, there is a suggestion to get this cropped image.

All you need to know is the original width and height of the image.

You can add /cX.Y.W.H/in the url to crop the image.

: - 1080x603. , , 1080x1080 ( ) 603x603.

: W = 603, H = 603, X = (1080-603)/2 = 238, Y = (1080-603)/2 = 238.

/c238.238.603.603/ url:

https://scontent.cdninstagram.com/hphotos-xtp1/t51.2885-15/s320x320/e35/c238.238.603.603/11950569_428157634035762_1539002513_n.jpg

https://scontent.cdninstagram.com/hphotos-xtp1/t51.2885-15/s320x320/e35/c238.238.603.603/11950569_428157634035762_1539002513_n.jpg

320x320, , , url:

https://scontent.cdninstagram.com/hphotos-xtp1/c238.238.603.603/11950569_428157634035762_1539002513_n.jpg

https://scontent.cdninstagram.com/hphotos-xtp1/c238.238.603.603/11950569_428157634035762_1539002513_n.jpg

UPD

real original size , API ( : " " → " → " "- > " Non square media) ".

:

:

https://api.instagram.com/v1/tags/nonsquare/media/recent?client_id=CLIENT-ID

:

...
images: {
    low_resolution: {
        url: "https://scontent.cdninstagram.com/hphotos-xpt1/t51.2885-15/e35/p320x320/10949090_860171600771180_267418389_n.jpg",
        width: 320,
        height: 400
    },
    thumbnail: {
        url: "https://scontent.cdninstagram.com/hphotos-xpt1/t51.2885-15/s150x150/e35/c0.135.1080.1080/10949090_860171600771180_267418389_n.jpg",
        width: 150,
        height: 150
    },
    standard_resolution: {
        url: "https://scontent.cdninstagram.com/hphotos-xpt1/t51.2885-15/sh0.08/e35/p640x640/10949090_860171600771180_267418389_n.jpg",
        width: 640,
        height: 800
    }
}
...

url /pWxH/, ( /p640x640/ 1080x1350 Instagram 640x800). (640x800) , .

:

URL- API:

https://scontent.cdninstagram.com/hphotos-xpt1/t51.2885-15/sh0.08/e35/p640x640/10949090_860171600771180_267418389_n.jpg

URL:

https://scontent.cdninstagram.com/hphotos-xpt1/t51.2885-15/sh0.08/e35/10949090_860171600771180_267418389_n.jpg

(640x640) URL:

https://scontent.cdninstagram.com/hphotos-xpt1/t51.2885-15/sh0.08/e35/p640x640/c0.80.640.640/10949090_860171600771180_267418389_n.jpg

(320x320 640x640) URL:

https://scontent.cdninstagram.com/hphotos-xpt1/t51.2885-15/sh0.08/e35/p640x640/c160.240.320.320/10949090_860171600771180_267418389_n.jpg

Cropped (320x320) url:

https://scontent.cdninstagram.com/hphotos-xpt1/t51.2885-15/sh0.08/e35/p320x320/c0.40.320.320/10949090_860171600771180_267418389_n.jpg
+5

Source: https://habr.com/ru/post/1614587/


All Articles