7

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
DMS-KH
  • 2,669
  • 8
  • 43
  • 73

4 Answers4

7

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;
Rameez Rami
  • 5,322
  • 2
  • 29
  • 36
  • For me it was an issue with using https://, modifying it to use http:// urls fixed the issue. Think it's a certificate problem on my localhost. – Andrew Schultz Mar 12 '21 at 06:44
3

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 !!

Mahesh Yadav
  • 2,416
  • 20
  • 23
0

Try it here:

php artisan storage:link

Mahdi Younesi
  • 6,889
  • 2
  • 20
  • 51
0

This is most probably because you may be using a self-signed certificate and it can't be verified properly.

InterventionImage uses stream_context_create which by default verifies the certificate.

Since Intervention Image doesn't directly allow a workaround via options, open vendor/intervention/image/src/Intervention/Image/AbstractDecoder and inside the function initFromUrl() add this

'ssl' => array(
   'verify_peer'   => false,
)

It will look something like this:

$options = [
   'http' => [
      'method'=>"GET",
      'protocol_version'=>1.1, // force use HTTP 1.1 for service mesh environment with envoy
      'header'=>"Accept-language: en\r\n".
       "User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36\r\n"
    ],
    'ssl' => array(
       // don't validate certificate
       'verify_peer'   => false,

       // alternatively you may add our certificate file path here and make
       // 'cafile'        => __DIR__ . '/cacert.pem',
       // 'verify_depth'  => 5,
       // 'CN_match'      => 'your-local-domain.com'
    )
 ];

$context  = stream_context_create($options);

It's not the perfect solution but it will allow you to continue to work locally.

Altin
  • 2,175
  • 3
  • 25
  • 47