containsParameter('image')) { return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, "Missing 'image' parameter"); } if(strlen($rpcRequest->getParameter('image')) > Configuration::getStorageConfiguration()->getUserDisplayImagesMaxSize()) { return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, "Image size exceeds the maximum allowed size of " . Configuration::getStorageConfiguration()->getUserDisplayImagesMaxSize() . " bytes"); } try { $decodedImage = base64_decode($rpcRequest->getParameter('image')); if($decodedImage === false) { return $rpcRequest->produceError(StandardError::RPC_BAD_REQUEST, "Failed to decode JPEG image base64 data"); } $sanitizedImage = Utilities::resizeImage(Utilities::sanitizeJpeg($decodedImage), 126, 126); } catch(Exception $e) { throw new StandardException('Failed to process JPEG image: ' . $e->getMessage(), StandardError::RPC_BAD_REQUEST, $e); } try { // Set the password RegisteredPeerManager::updateDisplayPicture($request->getPeer(), $sanitizedImage); // Remove the SET_DISPLAY_PICTURE flag SessionManager::removeFlags($request->getSessionUuid(), [SessionFlags::SET_DISPLAY_PICTURE]); // Check & update the session flow SessionManager::updateFlow($request->getSession()); } catch(Exception $e) { throw new StandardException('Failed to update display picture: ' . $e->getMessage(), StandardError::INTERNAL_SERVER_ERROR, $e); } return $rpcRequest->produceResponse(true); } }