Reputation: 1071
I am using hybridauth-3.7.1
from oauth library. https://github.com/hybridauth/hybridauth/releases
The library works perfectly so I have the following:
<?php
require_once 'hybridauth-3.7.1/vendor/autoload.php';
$config = [
'callback' => 'my_callback_url',
'keys' => [
'id' => 'my_app_id',
'secret' => 'my_secret'
],
];
$adapter = new Hybridauth\Provider\Reddit( $config );
$adapter->authenticate();
$userProfile = $adapter->getUserProfile();
$photo = $userProfile->photoURL;
If I echo the $photo I get: https://styles.redditmedia.com/t5_55fo22/styles/profileIcon_bblqmk8klas71.png?width=256&height=256&crop=256:256,smart&s=30a3bb6af945eadeaddb40271d2c0161ca82768d
now if I try to:
imagecreatefrompng($photo);
my logs return:
imagecreatefrompng( https://styles.redditmedia.com/t5_55fo22/styles/profileIcon_bblqmk8klas71.png?width=256&amp;height=256&amp;crop=256:256,smart&amp;s=30a3bb6af945eadeaddb40271d2c0161ca82768d ): failed`
So the url is properly returned in the echo, but as can be seen from the logs imagecreatefrompng is adding a weird &amp;
i have also tried
imagecreatefrompng(urldecode($photo));
and
$decoded_photo = urldecode($photo);
imagecreatefrompng($decoded_photo);
both return the same above error logs.
However if I manually type the url in it works fine.
imagecreatefrompng( 'https://styles.redditmedia.com/t5_55fo22/styles/profileIcon_bblqmk8klas71.png?width=256&height=256&crop=256:256,smart&s=30a3bb6af945eadeaddb40271d2c0161ca82768d' );
How can I get the returned image url to work with imagecreatefrompng?
Upvotes: 0
Views: 49
Reputation: 1071
The problem is when directly pasting the url as shown in the last example I was not realizing the cut and paste was different than the actual source.
This means although i was copying &height=256...
what was in the actual source was &=256...
Therefore when trying to imagecreatefrompng()
it was encoding already encoded &
thus resulting in &amp;
The fix was to change the $userProfile->photoUrl
as displayed below.
$photo = htmlspecialchars_decode($userProfile->photoURL);
imagecreatefrompng($photo);
Upvotes: 0