Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to init from given url in intervention/image": "^2.3

I want to save the images from google plus as below url it is work as well in local computer but I got below error when upload to ubuntu14.

$image = Image::make('https://lh6.googleusercontent.com/-Gcp_Wjj7yA0/AAAAAAAAAAI/AAAAAAAAAB8/hl1xcz4FnEI/photo.jpg')
            ->resize(100, 100)->save(public_path('image/userface/fuck.jpg'));

Errors

Unable to init from given url
like image 613
DMS-KH Avatar asked Feb 21 '17 10:02

DMS-KH


2 Answers

I have found a workaround for this problem. When we re-fetch the image, 99% it works, so i modified saving function to try to save for 3 times if it fails even then, we abort.

Solution

    $flag = true;
    $try = 1;
    while ($flag && $try <= 3):
        try {
            Image::make($path)->save(public_path("{$public_app_path}/" . $filename));
            //Image migrated successfully
            $flag = false;
        } catch (\Exception $e) {
            //not throwing  error when exception occurs
        }
        $try++;
    endwhile;
like image 137
Rameez Rami Avatar answered Nov 16 '22 11:11

Rameez Rami


In Image Intervention Package Parameters, that can be read by below URL.

http://image.intervention.io/api/make

2nd Point:- That URL of an image (allow_url_fopen must be enabled).

So please check that, the Image you are dealing with hosted on server that have allow_url_fopen PHP.INI directive enabled.

You can check whether it enabled or not by simple a single php statement as below.

echo ini_get('allow_url_fopen') ? 'Enabled' : 'Disabled';

If It is found disabled, please enabled it and then check. It works !!

like image 1
Mahesh Yadav Avatar answered Nov 16 '22 11:11

Mahesh Yadav