Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

imageUrl lorempixel is down #957

Closed
linxlad opened this issue Jul 7, 2016 · 33 comments
Closed

imageUrl lorempixel is down #957

linxlad opened this issue Jul 7, 2016 · 33 comments

Comments

@linxlad
Copy link

linxlad commented Jul 7, 2016

Is there any chance to introduce a backup when http://lorempixel.com/ is down?

@jremes-foss
Copy link
Contributor

Again? We could always make an additional check to source code where alternative (such as http://placehold.it/) is used if the check fails.

@fzaninotto
Copy link
Owner

On the contrary, I consider removing the image provider altogether, because I don't want to depend on a third-party with no SLA.

@okj579
Copy link
Contributor

okj579 commented Jul 11, 2016

I think a disclaimer to that effect would be sufficient. I still find the
provider very useful.

Though an external provider (like EmanueleMinotto/PlaceholdItProvider)
might be a better place for it?

@damiandennis
Copy link

lorempixel seem to be always down at the moment. it is useful though please don't remove it.

@atwright147
Copy link

atwright147 commented Jul 17, 2016

How about letting the user select where the images come from rather than making the source an internal variable?

I just spent an entire evening debugging some image problems, and it turns out the images had not downloaded. Maybe some feedback that the download had been unsuccessful would help...? :)

-- OR --

Fetch images from Flickr's Creative Commons images?

@ethanclevenger91
Copy link

If you're looking for an immediate solution, I haven't run into this with FillMurray, either. It offers less flexibility, but you can replace the following function in Providers/Image.php (obviously this will be lost if you update/start up somewhere else):

public static function imageUrl($width = 640, $height = 480, $category = null, $randomize = true, $word = null, $gray = false)
    {
        // $baseUrl = "http://lorempixel.com/";
        $baseUrl = "http://www.fillmurray.com/";
        // $url = "{$width}/{$height}/";
        $url = "{$width}/{$height}";

        // if ($gray) {
        //     $url = "gray/" . $url;
        // }

        // if ($category) {
        //     if (!in_array($category, static::$categories)) {
        //         throw new \InvalidArgumentException(sprintf('Unknown image category "%s"', $category));
        //     }
        //     $url .= "{$category}/";
        //     if ($word) {
        //         $url .= "{$word}/";
        //     }
        // }

        // if ($randomize) {
        //     $url .= '?' . static::randomNumber(5, true);
        // }

        return $baseUrl . $url;
    }

@gulaandrij
Copy link
Contributor

#963 fix this issue

@reno1979
Copy link

reno1979 commented Sep 21, 2016

public function robohash($name='robot',$width=200,$height=200,$background=FALSE,$secure=TRUE){

                    $baseUrl = ($secure) ? "https://robohash.org/" : "http://robohash.org";
                    $url = "{$name}.png?size={$width}x{$height}";

                    if ($background) {
                        $url .= "&bgset=bg" . $this->randomDigit;
                    }

                    return $baseUrl . $url;

                }

Or from the placeholdit provider [https://github.com/EmanueleMinotto/PlaceholdItProvider]

public function placeholdit($size, $format = 'gif', array $colors = array(), $text = null){
                    // $colors should be 100 or 100x100
                    // but can be ['height' => 100, 'width' => 100]
                    // or ['w' => 100, 'h' => 100]
                    if (is_array($size)) {
                        ksort($size);
                        $size = implode('x', $size);
                    }

                    $base = 'http://placehold.it/'.$size.'.'.trim($format, '.');

                    // $colors should be ['background', 'text']
                    // but can be ['text' => '000', 'background' => 'fff']
                    // or ['txt' => '000', 'bg' => 'fff']
                    // or ['foreground' => '000', 'background' => 'fff']
                    // or ['fg' => '000', 'bg' => 'fff']
                    ksort($colors);

                    if (2 === count($colors)) {
                        $base .= '/'.implode('/', $colors);
                    }

                    if ($text) {
                        $base .= '?'.http_build_query(array(
                            'text' => $text,
                        ));
                    }

                    return $base;
                }

@Kaijiro
Copy link

Kaijiro commented Oct 10, 2016

Maybe we could consider to choose in a configuration or something else like that the image provider that the user wants to have, so when one is down he can swap to another.

@ethanclevenger91
Copy link

ethanclevenger91 commented Oct 13, 2016

What about using something like Intervention Image to make a fake image? It'd certainly be less interesting, but it'd be reliable.

I'd be happy to work on a PR if @fzaninotto finds the idea passable.

@fzaninotto
Copy link
Owner

Because it adds a dependency on GD or ImageMagick.

@ethanclevenger91
Copy link

So I guess the question is, do you build in an image generator guaranteed to work and document its dependencies or build in one that fails silently and document that the end user's code should somehow account for that? I certainly don't have the right answer, but the shortcomings definitely need documented.

Is there any data on how many people are running PHP w/o at least GD? I guess it'd be hard to tell on dev environments.

@jremes-foss
Copy link
Contributor

As far as I know, PHP has internal features to build images. At least with PNG and JPEG. Not so sure with other formats though.

http://php.net/manual/en/function.imagejpeg.php
http://php.net/manual/en/image.examples-png.php

@Darival
Copy link

Darival commented Jul 5, 2017

maybe using another service like unsplash wich also has an api, and has better looking images.

@ethanclevenger91
Copy link

@Darival I like that idea, though the Unsplash API does require an application. Does everything get routed through one application deployed with Faker, or does that need to be configured by the end user?

@Darival
Copy link

Darival commented Jul 6, 2017

@ethanclevenger91 it does require app registration by the end user. This is better as an alternative option than as a replacement to lorempixel.

@sinkcup
Copy link

sinkcup commented Jan 10, 2018

Today https://lorempixel.com down again. I write a patch to switch to https://fakeimg.pl

https://gist.github.com/sinkcup/9cb5ef3495ad602417c276b0fd78b760

faker_image_url.patch

--- vendor/fzaninotto/faker/src/Faker/Provider/Image.php	2017-08-16 00:48:10.000000000 +0800
+++ Image.php	2018-01-10 15:25:31.384804140 +0800
@@ -30,22 +30,8 @@
      */
     public static function imageUrl($width = 640, $height = 480, $category = null, $randomize = true, $word = null, $gray = false)
     {
-        $baseUrl = "https://lorempixel.com/";
-        $url = "{$width}/{$height}/";
-
-        if ($gray) {
-            $url = "gray/" . $url;
-        }
-
-        if ($category) {
-            if (!in_array($category, static::$categories)) {
-                throw new \InvalidArgumentException(sprintf('Unknown image category "%s"', $category));
-            }
-            $url .= "{$category}/";
-            if ($word) {
-                $url .= "{$word}/";
-            }
-        }
+        $baseUrl = "https://fakeimg.pl/";
+        $url = "{$width}x{$height}/";
 
         if ($randomize) {
             $url .= '?' . static::randomNumber(5, true);

composer.json

    "scripts": {
        "post-install-cmd": [
            "patch -N -p0 < faker_image_url.patch || echo 'patch failed'"
        ]
    }

@daraul
Copy link

daraul commented May 10, 2018

Lorempixel seems to be down again, today. Any updates on an alternative?

@tomzx
Copy link
Contributor

tomzx commented May 12, 2018

A quick Google/Packagist search will lead you to find https://github.com/bruceheller/images-generator.

@tkrause
Copy link

tkrause commented Jun 13, 2018

The JS version of Faker although unrelated is using https://loremflickr.com/.

It seems like the best option would be to have a sane default but allow it to be configurable somehow. Many of these services have the same URL structure.

@fzaninotto
Copy link
Owner

Again, we won't fix this problem in Faker, but rather remove the Image formatter altogether.

Feel free to work on a standalone formatter for loremflickr, which seems to be a more reliable source.

@ChangePlaces
Copy link

ChangePlaces commented Jun 15, 2018

Please don't remove image support from faker - images are an essential part of web development.

It's as simple to just implement a random placeholder image with a solid background colour and basic text.

@ultreson
Copy link
Contributor

ultreson commented Aug 6, 2018

if people want an alternative to lorem pixel, i made a small fix to pass a different image generator as an argument, not incredibly elegant but it works since most of the alternatives have the same formatting
https://github.com/ultreson/Faker/tree/picture-providers

@spacedog4
Copy link

it'll be nice if you could pass the param to the baseUrl, I created a pull request about it #1542

@oliversarfas
Copy link

Lorempixel has been down for 2 days now

The package even dies silently, would be nice if it flagged the problem to the user, or allowed for multiple providers.

@spacedog4
Copy link

@oliversarfas I created a pull request for multiple providers #1542

@jonty-comp
Copy link

It took me 20 minutes to figure out why my image tests were returning boolean false...granted, it's a simple check but I didn't know where to start looking!

+1 for throwing an error when failing to pull an image, or indeed, for getting rid of the lorem pixel dependency altogether.

@falnyr
Copy link

falnyr commented Aug 14, 2018

@fzaninotto So you don't want any other third party image providers nor you want to generate the image directly in PHP? Or am I mistaken? What is the goal here?

@fzaninotto
Copy link
Owner

Right. the goal is to have in Faker core only stable and non-third-party dependent formatters. You can publish and share any formatter that doesn't fit these two criterions as third-party packages.

@marcosdipaolo
Copy link

So in the end no solution for now right?

@standaniels
Copy link

You could locally create images instead, for example by using this image generator. I've created that package so I can generate images instead of using faker to download them.

@mindplay-dk
Copy link

If anybody else is looking for fake profile photos, try thispersondoesnotexist.com - it's pretty great! I just downloaded 100 or so plausible-looking profile images, named them f for female, m for male, followed by a number, and I can use faker to randomly pick from those 👍

@mansourcodes
Copy link

mansourcodes commented Mar 10, 2020

I relpaced it with:

public static function imageUrl($width = 640, $height = 480, $category = null, $randomize = true, $word = null, $gray = false)
    {
        if ($randomize) {
            $randomize_number =  static::randomNumber(3, true);
        }
        $baseUrl = "https://i.picsum.photos/id/" . $randomize_number . "/";
        $url = "{$width}/{$height}.jpg";
        return $baseUrl . $url;
    }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests