D
D
Dmitry2016-04-28 14:43:40
2GIS
Dmitry, 2016-04-28 14:43:40

How to get an image from api 2gis for processing by the ResizeImageFile method?

Task:
Get a picture from static 2gis maps, resize it and put it in some folder on the server.
The CFile::ResizeImageFile method was chosen for work. The method parameters are $sourceFile. The path to the image to be changed is stored there. But if I insert the path to static.maps.2gis.com/1.0?zoom=15&size=500,350&mark... there, the method doesn't work.
Is it possible to somehow get a jpeg from a request, put it on a server, and only then give the path to the image in CFile::ResizeImageFile?
The option to immediately contact 2gis for the path to the picture is not considered, because this picture is used in PDF generation using MPDF and the picture sometimes crashes for unknown reasons. I want to hard-link images to the server

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2016-04-28
@ritual

I found the solution myself:
If allow_url_fopen is set to true on the server

//Отсюда забираем нужную картинку
$url = 'http://static.maps.2gis.com/1.0?zoom=16&size=535,660'; 

//Сюда выкладываем скачиваемую картинку
$path = '/server/path/name.jpg';
file_put_contents($path, file_get_contents($url));

Another solution via cURL
$ch = curl_init('http://static.maps.2gis.com/1.0?zoom=16&size=535,660');
$fp = fopen('/server/path/name.jpg', 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question