Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image won't load from Wikimedia #408

Open
Phu2 opened this issue Sep 23, 2024 · 4 comments
Open

Image won't load from Wikimedia #408

Phu2 opened this issue Sep 23, 2024 · 4 comments
Assignees

Comments

@Phu2
Copy link
Contributor

Phu2 commented Sep 23, 2024

Reported by @maipet via chat

bei lobid wird hier das Bild nicht angezeigt: https://lobid.org/gnd/13731518X - bei anderen geht es

Firefox says "Die Grafik "https://lobid.org/imagesproxy?url=https://commons.wikimedia.org/wiki/Special:FilePath/Wissenschaft%2C%20%C3%B6ffne%20dich%21%20Welche%20Infrastruktur%20braucht%20gute%20und%20offene%20Wissenschaft%3F%20%28Podiumsdiskussion%2C%2012.06.2019%29%20023.jpg?width=270" kann nicht angezeigt werden, weil sie Fehler enthält."

@Phu2 Phu2 self-assigned this Sep 25, 2024
@Phu2
Copy link
Contributor Author

Phu2 commented Sep 25, 2024

Tried to reproduce locally using this version of imagesproxy.php:

<?php
        $url = "https://commons.wikimedia.org/wiki/Special:FilePath/Wissenschaft%2C%20%C3%B6ffne%20dich%21%20Welche%20Infrastruktur%20braucht%20gute%20und%20offene%20Wissenschaft%3F%20%28Podiumsdiskussion%2C%2012.06.2019%29%20023.jpg?width=270";
        $url=str_replace(" ", "%20", $url);
        $fp = fopen ("test.jpg", 'w+'); 
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        #curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_FILE, $fp);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml","User-Agent: imagesproxy/0.2 (https://lobid.org/)"));
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        $filename = basename($url);

        switch (true) {
                case (stripos($filename,".ico") || stripos($filename,".png")):
                        $ctype="image/png";
                        break;
                case (stripos($filename,".jpg") || stripos($filename,".jpeg")):
                        $ctype="image/jpg";
                        break;
                case (stripos($filename,".gif")):
                        $ctype="image/gif";
                        break;
                case (stripos($filename,".svg")):
                        $ctype="image/svg+xml";
                        break;
                default:
                        $ctype="";
        }

        header('Content-type: ' . $ctype);
        #echo $output = curl_exec($ch);
        curl_exec($ch);
        curl_close($ch); 
        fclose($fp);
?>

Try php imagesproxy.php, the php-curl package is needed on your local system.
The downloaded image named test.jpg is a valid jpg file. 🤔

I wonder what the actual value of the url parameter is in this case. @fsteeg can you help?

Special characters like "!" in the file name may be the cause. The php script does some simple replacing already:

$url=str_replace(" ", "%20", $url); (see https://github.com/hbz/lobid/blob/master/gatsby/lobid/static/imagesproxy.php#L3)

@fsteeg
Copy link
Member

fsteeg commented Sep 25, 2024

@fsteeg can you help?

I've never worked with the proxy implementation before, but the problem seems familiar, I think we've had this issue before. Maybe @dr0i can help?

@Phu2
Copy link
Contributor Author

Phu2 commented Sep 25, 2024

@Phu2 Phu2 assigned dr0i and unassigned Phu2 Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants