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

Support for redirected images #5

Open
marcalj opened this issue Nov 19, 2013 · 6 comments
Open

Support for redirected images #5

marcalj opened this issue Nov 19, 2013 · 6 comments

Comments

@marcalj
Copy link

marcalj commented Nov 19, 2013

Example, show Facebook profile images:

https://graph.facebook.com/1415773021975267/picture
becomes:
https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash1/276836_1415773021975267_370639944_q.jpg

I'm looking at this, but hopefully I will use a hack in my code... Anyone had the same issue?

@marcalj
Copy link
Author

marcalj commented Nov 19, 2013

Why this jsFiddle is working with not same origin images?
http://jsfiddle.net/xKJB8/3/

@niklasvh
Copy link
Owner

It isn't.

"Uncaught SecurityError: Failed to execute 'toDataURL' on 'HTMLCanvasElement': tainted canvases may not be exported."

@marcalj
Copy link
Author

marcalj commented Nov 19, 2013

It works without errors at the first time, after opening the console and refresh full page doesn't work... strange.

@niklasvh
Copy link
Owner

If the image isn't in cache, it won't be drawn and as such the toDataURL just returns a blank canvas in base64. The image should be drawn only after it has been loaded

@marcalj
Copy link
Author

marcalj commented Nov 19, 2013

I've solved the issue using file_get_contents. This is the important change (quick&dirty code)

        $image = file_get_contents($_GET['url']);

        if (false === $image) {
            $fp = false;
        } else {
            fwrite($sf, $image);

            $finfo = new finfo(FILEINFO_MIME);
            $mime = $finfo->buffer($image) . PHP_EOL;

            $mime = preg_split('/;+/', $mime, -1, PREG_SPLIT_NO_EMPTY);

            if (is_array($mime)) {
                $mime = trim($mime[0]);
            }

            $allowMimes = Array(
                'image/jpeg', 'image/jpg', 'image/png', 'image/gif',
                'text/html', 'application/xhtml', 'application/xhtml+xml'
            );

            if (!in_array($mime, $allowMimes)) {
                $err = $mime . ' mime is invalid';
                $mime = false;
            }

            $fp = true;
        }
        fclose($sf);

@marcalj
Copy link
Author

marcalj commented Nov 19, 2013

Sorry, wrong repo!!!!! 💃 :S

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

2 participants