/** * Try to download and parse remote avatar * @param string $url * @param int $userId */ protected function parseAvatar($url, $userId) { // check if user is defined if ((int) $userId < 1) { return; } // check remote image extension $imageExtension = Str::lastIn($url, '.', true); if (!Arr::in($imageExtension, ['png', 'gif', 'jpg', 'jpeg'])) { return; } // try to get image binary data $imageContent = Url::download($url); if ($imageContent === null || Str::likeEmpty($imageContent)) { return; } // write image to filesystem $imagePath = '/upload/user/avatar/original/' . $userId . '.' . $imageExtension; $write = File::write($imagePath, $imageContent); if ($write === false) { return; } // try to write and resize file try { $fileObject = new FileObject(root . $imagePath); $avatarUpload = new FormAvatarUpload(); $avatarUpload->resizeAndSave($fileObject, $userId, 'small'); $avatarUpload->resizeAndSave($fileObject, $userId, 'medium'); $avatarUpload->resizeAndSave($fileObject, $userId, 'big'); } catch (\Exception $e) { if (App::$Debug) { App::$Debug->addException($e); } } }