rapid-porn

FREE
By yourComputerGuy | Updated 2 months ago | Entertainment
Popularity

9.4 / 10

Latency

650ms

Service Level

91%

Health Check

N/A

Back to All Discussions

in what format the image came from API, i cant render it

Rapid account: Eugene Veprytskyi
eugene.veprytskyi
7 months ago

issue

Rapid account: Jeankassiocheib 3
jeankassiocheib3 Commented 9 days ago

If you using PHP:

$images = new Images;

	$file = dirname(__FILE__) . "/media/media.jpg";
	
	$image = $images->getImage($term);
	
	if($image !== false){
		file_put_contents($file, $image);
	}

/*
Class with functions
*/
class Images{
private function isNotJson(string){ json_decode(string);
return json_last_error() !== JSON_ERROR_NONE;
}

public function getImage($term){
	
	$curl = curl_init();

	curl_setopt_array($curl, [
		CURLOPT_URL => "https://rapid-porn.p.rapidapi.com/photo?category=". $term,
		CURLOPT_RETURNTRANSFER => true,
		CURLOPT_ENCODING => "",
		CURLOPT_MAXREDIRS => 10,
		CURLOPT_TIMEOUT => 30,
		CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
		CURLOPT_CUSTOMREQUEST => "GET",
		CURLOPT_HTTPHEADER => [
			"X-RapidAPI-Host: rapid-porn.p.rapidapi.com",
			"X-RapidAPI-Key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
		],
	]);

	$response = curl_exec($curl);
	$err = curl_error($curl);

	curl_close($curl);

	if($err){
		return false;
	}else{
		
		if($this->isNotJson($response)){
			return $response;
		}else{
			return false;
		}
		
	}
	
}

}

Join in the discussion - add comment below:

Login / Signup to post new comments