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

Make Tonesque work with allow_url_fopen disabled #2

Open
mightymt opened this issue Jul 3, 2013 · 0 comments
Open

Make Tonesque work with allow_url_fopen disabled #2

mightymt opened this issue Jul 3, 2013 · 0 comments

Comments

@mightymt
Copy link

mightymt commented Jul 3, 2013

Currently Tonesque doesn't work with remote images when running in environments where allow_url_fopen is disabled because it uses the imagecreatefromgif, imagecreatefrompng and imagecreatefromjpeg functions.

I would suggest that in the color function you replace this...

switch ( $file ) {
    case 'gif' :
        $img = imagecreatefromgif( $image );
        break;
    case 'png' :
        $img = imagecreatefrompng( $image );
        break;
    case 'jpg' :
    case 'jpeg' :
        $img = imagecreatefromjpeg( $image );
        break;
    default:
        return false;
}

...with something like this...

if ( !in_array( $file, array( 'gif', 'jpg', 'jpeg', 'png' ) ) ) {
    return false;
}   

$response = wp_remote_request( $image, array( 'method' => 'GET' ) );

if ( is_wp_error( $response ) || empty( $response[ 'body' ] ) || $response['response']['code'] != 200 ) {
    return false;
}

$img = imagecreatefromstring( wp_remote_retrieve_body( $response ) );

I tested the above code on my shared hosted site where allow_url_fopen is disabled and it works as expected.

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

1 participant